For a map backed property, I’m able to return null...
# announcements
s
For a map backed property, I’m able to return null. I’m wondering if this is normal/expected.
Copy code
class MyClass {
    val map = mutableMapOf<String, Any?>().withDefault { null }
    var name: String by map
}
I cannot set
name
to
null
, but getting it returns
null
. This seems strange, given that the property has type
String
and not
String?
. Also, the IDE tells me the question mark in
name?.toString()
is unnecessary.
t
Method
toString
defined for all types - nullable or not
s
Indeed. Actual, my use case is not a String type, but an Android notification. Doing something like
notification?.icon
, the IDE tells me the question mark is unnecessary
l
a non-nullable variable being null definitely shouldn't be possible. report on youtrack
j
Null and non-null only works if everybody collaborates though. Android in particular has a habit of making things null at various times... the lifecycle is particularly important. I would ask on #C0B8M7BUY as they may have more specific knowledge...
e
in your project: NotNull and checked in Compilation time out of your reach: may let your NotNull be null
s
Looks like it’s already been reported: https://youtrack.jetbrains.com/issue/KT-27498