https://kotlinlang.org logo
#getting-started
Title
# getting-started
j

Jasin Colegrove

01/26/2022, 2:15 PM
https://kotlinlang.org/docs/object-declarations.html#companion-objects under companion objects there is this "Class members can access the private members of the corresponding companion object." Can someone show me the extent of what this means with a code example?
l

Leon W

01/26/2022, 2:21 PM
Copy code
class CompanionTest {
    companion object {
        private val defaultName = "name"
    }

    var name = defaultName
}
We can assign the private member
defaultName
, which is located in the companion object, to the class member
name
.
4 Views