jstuyts-squins
01/16/2018, 10:16 AMcb
is indeed Any
, but I can still access framebufferSize
. This is in a JVM module (apply plugin: 'kotlin'
) of a multi-platform project using Kotlin 1.2.10:
val cb = object {
val framebufferSize = 1
}
println(cb.framebufferSize)
elect
01/16/2018, 10:24 AMcb.framebufferSize
in a custom setter?jstuyts-squins
01/16/2018, 10:31 AMoperator fun set(...)
? No, and that makes sense. You cannot access a variable in its initializer. This applies to both cb
and framebufferSize
Andreas Sinz
01/16/2018, 10:45 AMNote that anonymous objects can be used as types only in local and private declarations. If you use an anonymous object as a return type of a public function or the type of a public property, the actual type of that function or property will be the declared supertype of the anonymous object, or Any if you didn't declare any supertype. Members added in the anonymous object will not be accessible.
Andreas Sinz
01/16/2018, 10:45 AM