How write this in Kotlin Class MyClass implement ...
# android
How write this in Kotlin Class MyClass implement Serializable { Int id; String name; // getters & setters }
Copy code
data class MyClass(
  val id: Int,
  val name: String
) : Parcelable
Thanks my friend
Wait, why does serializable replaced with parcelable? Parcelable is not a requirement, Kotlin supports standard Java Serialization too, but you should be careful with null ability Also it's not a requirement to make this class data and even move properties to constructor If you show full example of would be possible to suggest what is direct translation to Kotlin. Also java to Kotlin converter can do this automatically
They can annotate it with
as well
@Serializable is also not the same! It will not make class to work with Java Serialization
I do not say that
is better than Parcelable on Android or usage of Kotlinx Serialization My point is that question was not “what is best way to serialize class in Kotlin”, it was about how to convert Java class to Kotlin. And answer is that just implement Serializable interface, same as in java, and yes, use Kotlin properties and constructor initialiser as you suggested Parcelable or kotlinx,serialization is much wider topic, you cannot use any of them and keep old code working, it requires migration of existing code