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

**URL:** <https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467>\
**Category:** Uncategorized\
**Created:** [September 18, 2014, 2:19pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467 "2014-09-18T14:19:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![evacchi](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@evacchi](https://discuss.kotlinlang.org/u/evacchi)\
**Post date:** [September 18, 2014, 2:19pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/1 "2014-09-18T14:19:00Z")

</div>

```
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

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [September 18, 2014, 2:21pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/2 "2014-09-18T14:21:50Z")

</div>

Something's wrong with your example:

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

Both options compile for me

---

<div class="post-metadata">

**Author:** ![evacchi](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@evacchi](https://discuss.kotlinlang.org/u/evacchi)\
**Post date:** [September 18, 2014, 2:47pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/3 "2014-09-18T14:47:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [September 18, 2014, 5:57pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/4 "2014-09-18T17:57:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![evacchi](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@evacchi](https://discuss.kotlinlang.org/u/evacchi)\
**Post date:** [September 19, 2014, 2:23pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/5 "2014-09-19T14:23:07Z")

</div>

thanks for the prompt reply, will do

---

<div class="post-metadata">

**Author:** ![reisi007](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/reisi007/32/2636_2.png) [@reisi007](https://discuss.kotlinlang.org/u/reisi007)\
**Post date:** [February 14, 2018, 1:21pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/6 "2018-02-14T13:21:56Z")

</div>

This is still the case in Kotlin 1.2!

---

<div class="post-metadata">

**Author:** ![SackCastellon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sackcastellon/32/4553_2.png) [@SackCastellon](https://discuss.kotlinlang.org/u/SackCastellon)\
**Post date:** [February 14, 2018, 3:08pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/7 "2018-02-14T15:08:04Z")

</div>

> [@reisi007](#):
>
> 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>) {
    println(String::class.allSuperclasses)
}

```

Which prints:

```
[class kotlin.Comparable, class kotlin.Any, class kotlin.CharSequence, class java.io.Serializable]

```

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [February 14, 2018, 6:43pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-kotlin-int-etc-do-not-implement-java-io-serializable/467/8 "2018-02-14T18:43:23Z")

</div>

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.
