You need to change Class<I> to Class<out I>:
kotlinfun <I> calculateStuff(valueType: Class<out I>, defaultValue: I): I {return defaultValue;}
You can also do this using reified type parameters:
kotlininline fun <reified I> calculateStuff(defaultValue: I): I {// do some workreturn defaultValue;}
Usage:
kotlinval myVar1 = calculateStuff("") // myVar1 is Stringval myVar2 = calculateStuff<String?>(null) // myVar2 is String?