Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 214 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I implement Serializable in Kotlin so it also works in Java?

#1
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?
Reply

#2
> 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...
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through