Hello, I'm getting really confused about a type mi...
# getting-started
m
Hello, I'm getting really confused about a type mismatch error:
Copy code
abstract class X
data class Y() : X(), Serializable
data class Z() : X(), Serializable

var firstValue: X = Y() -> Type mismatch
var secondValue: X = Z() -> Type mismatch
Is there something I am missing?
d
Your code does not compile, because data classes must have at least one primary constructor parameter. I don't get the "type mismatch" error.
2
m
I do have constructor parameters in the data classes, I just removed them for the sake of question.
I'm getting the type mismatch errors when I try to instantiate the variables and I don't get it why.
d
usually type mismatch comes with more detailed error message... you have any?
s
This code compiles and runs
Copy code
abstract class X
data class Y(val y: Int) : X(), Serializable
data class Z(val z: String) : X(), Serializable

var firstValue: X = Y(0)
var secondValue: X = Z("")