Hi, what is the difference between `val obj : Obje...
# android
r
Hi, what is the difference between
val obj : Object = Object()
and
val obj: Object get() = Object()
?
z
The former initialized the
Object
once and stores it in a backing field which is returned every time the
obj
property is read. The latter reads
Object
every time the
obj
property is read (did you mean
Object()
there? in that case it would create a new instance on every read.)
🙏 1
e
assuming you write
get()
not
@get()
☝🏻 1
and you'd typically use
Any
not
Object
in Kotlin code
z
Oh yea, pretty sure
@get()
won’t even compile
r
yeah..I just typed this quickly sorry for the typos :)