You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/03_special_classes/01_Data classes.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Data Classes
2
2
3
-
[Data classes](https://kotlinlang.org/docs/reference/data-classes.html) make it easy to create classes that are used to store some values. Such classes are automatically provided with methods for copying, getting a string representation, and using instances in collections.
3
+
[Data classes](https://kotlinlang.org/docs/reference/data-classes.html) make it easy to create classes that are used to store values. Such classes are automatically provided with methods for copying, getting a string representation, and using instances in collections.
Copy file name to clipboardExpand all lines: examples/03_special_classes/02_Enum.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Enum Classes
2
2
3
-
[Enum classes](https://kotlinlang.org/docs/reference/enum-classes.html) are used to model types that represent a finite set of distinct values, such as directions, states, modes and so forth.
3
+
[Enum classes](https://kotlinlang.org/docs/reference/enum-classes.html) are used to model types that represent a finite set of distinct values, such as directions, states, modes, and so forth.
Copy file name to clipboardExpand all lines: examples/03_special_classes/03_Sealed Classes.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ fun main() {
25
25
</div>
26
26
27
27
28
-
1.Defining a sealed class.
29
-
2.Defining subclasses. Note that all subclasses must be in the same file.
30
-
3.Using an instance of the sealed class as an argument in a `when` expression.
28
+
1.Defines a sealed class.
29
+
2.Defines subclasses. Note that all subclasses must be in the same file.
30
+
3.Uses an instance of the sealed class as an argument in a `when` expression.
31
31
4. A smartcast is performed, casting `Mammal` to `Human`.
32
32
5. A smartcast is performed, casting `Mammal` to `Cat`.
33
33
6. The `else`-case is not necessary here since all possible subclasses of the sealed class are covered. With a non-sealed superclass `else` would be required.
Copy file name to clipboardExpand all lines: examples/03_special_classes/04_Object.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Object Keyword
2
2
3
-
Classes and objects in Kotlinwork the same way as in most object-oriented languages: a *class* is a blueprint, and an *object* is an instance of a class. Usually, you define a class and then create multiple instances of that class:
3
+
Classes and objects in Kotlin work the same way as in most object-oriented languages: a *class* is a blueprint, and an *object* is an instance of a class. Usually, you define a class and then create multiple instances of that class:
In Kotlin you also have also the [**object** keyword](https://kotlinlang.org/docs/reference/object-declarations.html). It is used to obtain a *data type with a single implementation*.
33
+
In Kotlin you also have the [**object** keyword](https://kotlinlang.org/docs/reference/object-declarations.html). It is used to obtain a *data type with a single implementation*.
34
34
35
35
If you are a Java user and want to understand what "*single*" means, you can think of the **Singleton** pattern:
36
36
it ensures you that only one instance of that class is created even if 2 threads try to create it.
@@ -40,8 +40,8 @@ Why lazy? Because it will be created once when the object is accessed. Otherwise
40
40
41
41
### `object` Expression
42
42
43
-
Here is a typical basic usage of an `object`**expression**: a simple object/properties structure.
44
-
There is no need in class declaration: you create a single object, declare its members and access it within one function.
43
+
Here is a basic typical usage of an `object`**expression**: a simple object/properties structure.
44
+
There is no need to do so in class declaration: you create a single object, declare its members and access it within one function.
45
45
Objects like this are often created in Java as anonymous class instances.
0 commit comments