class A {
val fields = object {
val hello = "hello"
}
fun foo() {
val hello = fields.hello // unresolved reference: hello
val f = object {
val hello = "hello"
}
val hello2 = f.hello // compiles fine
}
}
Apparently, this.fields resolves to kotlin.Any, while the local val f to the anonymous object of type mypackage.A.foo.<no name specified> which is the same I would expect for A.fields
As option which avoid publishing anonymous class outside of using block can be also used next semantic: val value = object ClassName {...} by analogue of object declaration.
class Properties(val source: Map<String, String>) {
val system = object System {
val os: String by source
val version: String by source
}
val db = object Db {
val username: String by source
val password: String by source
val extended = object Extended {
val poolSize: String by source
}
}
}