How to reference outer object's property?

50 Views Asked by At

Consider the following code:

class SomeClass {

    companion object {
        val str = "My String"
        object AnotherObject {
             fun foo(str: String) {
                  return str + //companion object's str
             }
        }
    }
}

How to reference SomeClass::companion object::str from AnotherObject::foo?

1

There are 1 best solutions below

0
Vlad Guriev On BEST ANSWER

Please try as follows:

class SomeClass {
    companion object {
        val str = "My String"
        object AnotherObject {
            fun foo(str: String): String {
                return str + SomeClass.str
            }
        }
    }
}