Attention: gson.fromJson will return a non-nullable type whereas gson.fromJson<MyType?> will return a nullable type. Therefore the code gson.fromJson("null") is correct and will throw a null-pointer exception!
But it is not possible to use MyType?, Kotlin says the following: Type argument not within its bounds, which it's expected since it's expecting Any, non-nullable.
From the readme:
But it is not possible to use
MyType?
, Kotlin says the following:Type argument not within its bounds
, which it's expected since it's expectingAny
, non-nullable.