Kotlin.String, kotlin.Int, etc. do not implement java.io.Serializable

class Foo<T: java.io.Serializable>
fun f() {
    Foo<String>() // does not compile
    Foo<java.io.String>() // compiles

e.g., spring data uses this for specifying the ID of the repository

public interface MongoRepository <T, ID extends java.io.Serializable> …

is this by design? should I file a bug?

EDIT: fixed missing type args


Something's wrong with your example:

class Foo
fun f() {
    Foo() // does not compile
    Foo() // compiles

Both options compile for me


sorry, the forum software ate the type arguments :-)


I see the problem now, yes, file an issue please


thanks for the prompt reply, will do


This is still the case in Kotlin 1.2!


The code works fine in Kotlin 1.2

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>) {

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.