Using the interop automatisms Kotlin has for nullability, a method like this gets the proper signature in Kotlin:
@NonNull
public String foo(@NonNull String bar) {
return "bar";
}
Now lift the principle to collections (or other generics, I guess):
@NonNull
public Set<String> foo(@NonNull Collection<String> bar) {
return new HashSet<String>();
}
This shows in Kotlin as
foo(bar: (Mutable)Collection<String!>) : (Mutable)Set<String!>
I'm fine with (Mutable)
, but how do I get rid of the platform types in the type parameters? That is, how do I write or annotate the Java function so that I see Set<String>
(or Set<String?>
, for that matter) from Kotlin?
Using Set<@NonNull String>
is not allowed ("'@NonNull' not applicable to type use").
If it makes a difference, I use the Findbugs annotations (via Spotbugs). My perspective is that of a (Java) library provider who wants to enable as seamless use from Kotlin as possible.