Is there a preferred way to make a class that won'...
# getting-started
s
Is there a preferred way to make a class that won't be inherited from? I am going to have specific "activity" classes which all hold a load of variables. I don't want to use this class to make objects though, I judt want ot use it as a one off object which i can call all the variables from. Do i still just do a normal class?
y
Sounds like you want an
object
(docs)
j
Not sure what you mean exactly. First it looked like you wanted a final class (which is actually the default), but then it looks like you need a singleton (which, as Youssef mentioned, done with
object
in Kotlin)
s
Thanks I wasn't aware you cpukd make an object without a class to inherit from. Thanks!
k
It's not an "object without a class" (at least not in Kotlin/JVM). It's a class that's declared using the
object
keyword. That class has a lot of generated code behind the scenes which ensures you can only ever have a single instance of it. And the syntax when using this instances also ensures that.
s
Cheers mate!