39

I have some code that I've been using for years in Java, but need it in Kotlin (its interfaces extend collections interfaces). Some classes are serializable. When I try the obvious, I get "Cannot access 'Serializable': it is internal in kotlin.io":

class Foo(val someField:Int): Serializable {
    companion object {
        private const val serialVersionUID = 20180617104400L
    }
}

So, do I just import java.io.Serializable, or will that cause other issues?

snv
  • 133
  • 1
  • 11
GlenPeterson
  • 4,866
  • 5
  • 41
  • 49

1 Answers1

35

do I just import java.io.Serializable

Yes. Just be aware that Kotlin uses @Transient annotation instead of a keyword.

Of course, Java serialization does have its issues, but there's no difference in that respect between Kotlin and Java, and if you are happy with your current code...

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487