Can't call a function with type variables


#1

The function is defined in java as:   <K extends Comparable, V> NavigableMap<K, V> createTreeMap(String name);

I’m trying to call it in Kotlin as:
val header = db.createTreeMap<String, Array<String>>(“header”)

The Kotlin compiler complains that:
  Type argument is not within its bounds: should be subtype of ‘java.lang.Comparable<out jet.Any?>?’

And hightlights the first String type above.

Am I missing something or is this a bug?

Thanks,

Dave


#2

The problem is that the String in your example is not a java.lang.String, but a Kotlin String.

You can work around this problem by specifying java.lang.String explicitly, but then you’d need to cast Kotlin strings to Java strings sometimes (and the compiler will issue a warning, although the code works fine).
We are working on this issue.