1

I have read everywhere that Java Serializable is much slower than Parcelable . Is it the same case for Kotlin Serializable? Or is Kotlin Serializable equally fast as Kotlin Parcelable? Using Serializable seems to much simpler and i wanted to know if in Kotlin its fine to use Serializable instead of Parcelable.

Dishonered
  • 6,544
  • 7
  • 23
  • 43
  • 1
    Test and measure. – user207421 May 28 '18 at 05:04
  • Check [this](https://stackoverflow.com/questions/3323074/android-difference-between-parcelable-and-serializable?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – sneharc May 28 '18 at 05:05
  • Native Kotlin Serialization, I quote from the official GitHub page, "is still highly experimental". So it's nothing like an alternative to the bog-standard Java Serialization or Android's native Parcelable. – Marko Topolnik May 28 '18 at 06:44

3 Answers3

3

Kotlin standard library doesn't have its own definition of Serializable, if you have code using it you'll notice import java.io.Serializable. So it's exactly as fast.

There is @Serializable from kotlinx.serialization (thanks to Marko Topolnik for reminding me of it), but it works very differently and is not easier to use than @Parcelize (see below).

Using Serializable seems to much simpler

But here you have an advantage: in Kotlin it's just as easy, just use the @Parcelize annotation (see the design document as well).

Alexey Romanov
  • 154,018
  • 31
  • 276
  • 433
2

Yes, Serializable is exactly more simple than Parcelable but Parcelable is much more faster than Serializable. If your application not require maximize performance optimized, Serializable still fine.

Johnny Ngo
  • 94
  • 4
2

Is it the same case for Kotlin Serializable? Or is Kotlin Serializable equally fast as Kotlin Parcelable? Using Serializable seems to much simpler and I wanted to know if in Kotlin its fine to use Serializable instead of Parcelable.

Whether you are using JAVA or Kotlin, the internal working of Serializable and Parcelable will still remain same. Hence, even for Kotlin its recommend using Parcelable for better and faster performance.

Hope it helps.

Bhavesh Patadiya
  • 25,555
  • 14
  • 76
  • 105