class Foo<T : java.io.Serializable>
fun f() {
Foo<String>() // compiles
Foo<java.lang.String>() // compiles, and warning suggesting to use kotlin.String
}
In fact, you can check the String implements java.io.Serializable by running this code:
import kotlin.reflect.full.allSuperclasses
fun main(args: Array<String>) {
println(String::class.allSuperclasses)
}
Which prints:
[class kotlin.Comparable, class kotlin.Any, class kotlin.CharSequence, class java.io.Serializable]
Indeed, both String an Int are internally transformed into appropriate Java classes which are serializeable.
I’ve recently encountered another problem. KClass is not serializable, so I had to use Java Class instead. I do not see any reason not to make KClass serializable as well.