mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-11 09:14:39 +02:00
[Kotlin/en] correct object clarification (#2413)
* Kotlin: correct object clarification * Kotlin: correct object clarification
This commit is contained in:
@@ -337,7 +337,7 @@ enum class EnumExample {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
The "object" keyword can be used to create singleton objects.
|
The "object" keyword can be used to create singleton objects.
|
||||||
We cannot assign it to a variable, but we can refer to it by its name.
|
We cannot instantiate it but we can refer to its unique instance by its name.
|
||||||
This is similar to Scala singleton objects.
|
This is similar to Scala singleton objects.
|
||||||
*/
|
*/
|
||||||
object ObjectExample {
|
object ObjectExample {
|
||||||
@@ -346,6 +346,11 @@ object ObjectExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun useObject() {
|
||||||
|
ObjectExample.hello()
|
||||||
|
val someRef: Any = ObjectExample // we use objects name just as is
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Further Reading
|
### Further Reading
|
||||||
|
Reference in New Issue
Block a user