bbaldino
07/24/2020, 5:35 PMT bounded by Any and call a method which returns a T, but in this case T is a java type (an enum) and the method (defined in java) returns null. I expected an exception to be thrown here, but instead the value of null trickles up just fine, and a (kotlin) method which is set to return a value T : Any ends up happily returning null. Is it expected that this won't throw somewhere? Is this just a limitation of interacting with Java types from kotlin?bbaldino
07/24/2020, 5:41 PMstreetsofboston
07/24/2020, 5:48 PMMyEnum!, with the exclamation mark !).
Values of this type can be null but can be assigned to non-nullable variables.
At some point, when you finally access the platform-type value and expect it to be not null, you’ll get a null-pointer-exception.bbaldino
07/24/2020, 5:51 PMbbaldino
07/24/2020, 6:11 PMbbaldino
07/24/2020, 6:12 PMbbaldino
07/24/2020, 6:12 PMstreetsofboston
07/24/2020, 6:16 PMreturn statement as well… (get(): NewType =), but I guess it doesn’t….bbaldino
07/24/2020, 6:16 PMbbaldino
07/24/2020, 6:22 PMConverter#get to:
fun get(): NewType = converter(originalValue).also {
if (it == null) {
println("null!")
}
}
then kotlin warns me the check is redundant (since it thinks it can't be null), but it does print null!... 😛bbaldino
07/24/2020, 6:50 PMbbaldino
07/24/2020, 7:22 PMbbaldino
07/24/2020, 7:23 PMval a = Converter<String, MyEnum>("blah") { MyEnum.fromString(it) }
println(a.get())
but this will print `null`:
val c = Converter<String, MyEnum>("blah", MyEnum::fromString)
println(c.get())