Set nullability of existing java methods


#1

I currently maintain Kotson, a Kotlin library that allows a kotlin-esque way of using Google's Gson.

In the library, I have several lines such as :

public val JsonElement.string : String get() = asString


Which is only a way to call .asString (.getAsString() in Java Gson) but with a returned String and not String!

Now, the IDE proposes to Kotson’s user both .asString: String! and .string: String. Which is not really ideal.

Is there a way I could modify the library so that kotson’s users use .asString but with strong nullability ?


#2

Annotations in the Java code can change platform types into proper Kotlin types. You used to be able to store them in external XML files but I think that support was removed. Probably now you must modify the upstream library itself. And unfortunately, it seems there's no way to specify a default - every parameter must be individually tagged with whether it's nullable or nonnull.