dumb question, is there a way to make a superclass...
# getting-started
m
dumb question, is there a way to make a superclass for data classes? I'm making a "message passing" architecture where I want a superclass
Message
and subclasses are polymorphic data
f
Data class can inherit normal class.
👎 1
Make normal class as
open
b
i would use interfaces over superclasses for data objects unless there was a specific need
👍 2
f
@bj0 arent interface variables
static
and
final
, thereby making them a constant? Im not sure if we can use mutable
var
inside interface.
b
no, why would they be static and final??
b
that doesn't hold true for kotlin
mostly because kotlin doesn't have publically accessible fields,
var field
will generate you two functions (in jvm bytecode)
getField
and
setField
f
What will be returned if i just declare a `var`in interface? Initialisation is not done yet
I read lateinit var is not permitted in kotlin
b
well you can't instantiate an interface, so any class or object that inherits the interface will have to do the initialization
you can see if things work in kotlin by trying them at: https://try.kotlinlang.org
f
Sure