I'm new to Kotlin and I don't know why compiler complains about this code:
data class Test(var data : String = "data")
fun test(){
var test: Test? = Test("")
var size = test?.data.length
}
Compiler complains with test?.data.length
, it says that I should do: test?.data?.length
. But data variable is String
, not String?
, so I don't understand why I have to put the ?
when I want to check the length.