https://kotlinlang.org logo
#announcements
Title
# announcements
l

LastExceed

08/25/2019, 8:04 AM
what is the purpose of
object
? isn't it basically same as top level members in a separate package?
j

jmfayard

08/25/2019, 8:07 AM
object Elvis
defines a singleton (there is only one Elvis) Not the same because after imports they will look like
Elvis.GREATEST_HITS
and
GREATEST_HITS
. The former is better IMHO
l

LastExceed

08/25/2019, 8:09 AM
so basically the purpose is just structure (where to find a function) and accessibility (public/private/ect) right?
k

karelpeeters

08/25/2019, 8:22 AM
And they can implement interfaces, I also use them for "do nothing" interface implementations.
For example the stdlib has the empty list, set and iterator as objects I think.
2 Views