poohbar
08/10/2022, 9:47 PMopen class Animal<T1, T2>
class Cat<I> : Animal<I, List<I>>()
val x: Animal<String, List<String>> = Cat()
however trying to do the same instantiation in java fails:
Animal<String, List<String>> x = new Cat<String>() // error
Is there something I can do to improve the generics in the Kotlin code so that they can be used from Java just like from Kotlin?ephemient
08/10/2022, 9:55 PMclass Cat<I> : Animal<I, List<@JvmSuppressWildcards I>>()
poohbar
08/10/2022, 9:56 PMephemient
08/10/2022, 11:31 PMList
is declared with an out
type parameter, the translation to Java is normally List<? extends String>
. this is more general than a Java List<String>
(well, not for String
in particular because it's final
, but the typechecker doesn't know that)