KoxAlen
12/03/2020, 3:48 PMsealed class Fragment {
abstract val name: String?
}
data class Gauge(
@field:JvmField
override val name: String? = null,
@field:JvmField
val maxValue: Int
) : Fragment()
compiles fine w/o any warning (jvm target ofc)
but fails in runtime
val foo: Fragment = Gauge("name", 7)
foo.name
which makes some sense because by just looking at Fragment calling getName
seems safe
But what is weirder
Gauge("name", 7).toString() // or other generated data class method like equals/hashcode/...
also tries to call getName instead of just using the field... (which seems like a bug on its own)
Ideally the compiler could generate a synthetic getName
for the data class in this case to fulfil both contracts
otherwise shouldn't this at least be a error(/warning maybe?) from the compiler?