Good morning from japan. So now i am stucking in c...
# getting-started
t
Good morning from japan. So now i am stucking in companion object.
Copy code
class Myclass(val name: String, val age: Int) {
    private someProperty = .....
    private someProperty = .....
    companion object {
        @JvmStatic
        val instance = Myclass(name = ??  , age = ??)
    }
}
how to set name and age value inside the companion object?
a
Your code seems to be valid. What is troubling you?
t
Thanks.. my problem is here
val instance = MyClass(name = "name", age = 42)
i don’t want to put name value and age value directly. Because i have to call this class from Java.
a
so do you want to use the
MyClass
as a singleton with initializing like this snippet? (below code is invalid)
t
@atsushi-koshikizawa yes definitely, i just thought, i can use the property value of name and age inside companion object and it’s totally wrong.
a
yes, properties in constructor are dynamic values, not static. so they cannot be referred in companion object.