Hi, could someone tell me how to use one companion object field in another one ? why I get some err...
x
Hi, could someone tell me how to use one companion object field in another one ? why I get some error like
Variable 'xxx' must be initialized
? look the code below:
Copy code
class CompanyResource {
    companion object {
        val allNames: Map<String, String> =
            mapOf(
                someone.first to someone.second // error: Variable 'someone' must be initialized
            )

        val someone =
            Pair<String, String>(
                "peter" , "blunt"
            )
    }
}
l
forward reference, i think. put
someone
above
allNames
๐Ÿ˜€ 1
s
Class/object properties are initialized in the order theyโ€™re declared.
โœ… 2
๐Ÿ‘๐Ÿพ 1
๐Ÿ‘ 2
x
yes it works!