By default, kotlin sees any java method's return type and parameter types as nullable (because, for example, no one guarantees the return value is not null). So kotlin sees the method
public BigInteger add(BigInteger value)
as
public add(value : BigInteger?) : BigInteger?
But sometimes library guarantees non null returned value (actually in the example above) or requires non null arguments. In such cases there should be a special header that specifies declarations of java methods (makes some nullable types non null). These special headers are now ready for some part of java standard library, but the common mechanism of creating these headers for other libraries is under development.
Thank you very much for this elaborate explanation. So, I assume by calling the sure() API the ‘same’ value is returned but without the question mark in the signature.
But note sure() throws NullPointerException if value is null so this is unsafe feature and you should use it ONLY when you are absolutely sure the value will never null.
For example,
val p = Pattern.compile(“[0-9]+”).sure()
is valid since we now Pattern.compile will never return null.