are top-level variables outside of a class referre...
# getting-started
f
are top-level variables outside of a class referred to as "properties"?
m
I don’t think so, since properties are related to a class: they presume implicit accessors, which don’t exist for top level declarations. They’re just variables or constants, global or not depending on their visibility
f
but they have a generated getter/setter
m
I assumed so
Kotlin has had top-level functions and properties from day one.
m
Oh wow… didn’t know that, thanks!
m
I did test whether top-level properties were allowed last week while preparing presentation, I was interested whether one can expect/actual properties (spoiler, you can)
f
thank you very much
m
@Matteo Mirk They end up being class properties in the bytecode because there's no choice, and as per above, they add getter/setter for convenient/idiomatic access in Java.
f
You can also override get/set like for class properties. Is that something that is used in real code?
m
Yeah, now that Marko pointed it out I know. Makes sense: translating to Java you have no other choice other than making those static members of a top-level class. Thanks for the clarification.
f
top-level properties can never be declared without initialization, unless they're nullable or use lateinit/lazy, right?