zsperske
12/23/2020, 6:19 PMpublic static <T> MyFactory<T> of(Class<T> baseType) { ... }
and you wanted to write a kotlin extension method like:
fun <T> MyFactory<T>.withSubTypes(types: List<Class<T>) {
var factory = this
types.forEach { factory = factory.withSubType(it) }
return factory
}
How do you properly type the static method? If you write something like:
val factory = MyFactory.of(MyClass::class.java)
.withSubTypes(listOf(...))
You'll get a syntax error on your list: Type mismatch. Required: Nothing Found: MyClass
. Adding explicit type arguments doesn't help.Vampire
12/23/2020, 7:03 PMfun <T> MyFactory<T>.withSubTypes(types: List<Class<T>) {
?zsperske
12/23/2020, 7:12 PMzsperske
12/23/2020, 7:22 PMzsperske
12/23/2020, 7:22 PMtypes: List<Class<T>
to be types: List<Class<out T>