andym
02/08/2024, 4:28 PM@JvmInline
value class MyValueClass(private val value: String) {
override fun toString() = value
}
I need the toString()
override because there are callers in the frameworks I need that call it, and I don't want the extra markup: MyValueClass(value="Some value")
I have an nullable argument of type MyValueClass:
fun myFunction(currentValue: MyValueClass? = null)
When I pass no value, or even if I explicitly pass null
, then myFunction
receives currentValue
as "null"
.
Is this an auto-promotion? When I explicitly pass a string value, compilation fails with a Type Mismatch, as I'd expect. But why does a null value silently become "null", instead of a null MyValueClass
? (Or in bytecode, just a String?
?Sam
02/08/2024, 4:38 PMKlitos Kyriacou
02/08/2024, 4:45 PMprintln(currentValue)
prints "null" or that the fact that null.toString() == "null"
.andym
02/08/2024, 5:00 PMandym
02/08/2024, 5:02 PMYoussef Shoaib [MOD]
02/08/2024, 5:38 PMandym
02/08/2024, 7:45 PM