Parcelable


#1

Parcelable classes need to implement two methods, and static field CREATOR http://developer.android.com/reference/android/os/Parcelable.html

Its quite the same as data class concept.
Can it be implemented the same way?

parcelable class MyClass(val …)?

There are plenty of annotation processing code generation tools, but it will be super cool to implement it “inside” kotlin

I would love to contribute such thing but need some starting points and language designers accept


#2

We are trying to keep the language platform-independent. Adding parcelable as a built-in modifier does not seem sensible, although the use case is very credible.


#3

Yes, i understand that.
Does it mean that we need android-specific compiler, ide plugin that aware of environment and so on?

Can it somehow be solved with kotlin-android-extensions?


#4

This is something worth generalizing. Parcelable for Android. Protobufs for other things. JSON or XML for yet others. Maybe a good place to look for inspiration is Go, where classes implement a small interface and are then compatible with a variety of different encoders.


#5

What about forcing the companion object to inherit from the companion object of its supertypes through delegation?

The problem in this case is that CREATOR is a field, not a method, and delegation cannot handle that.


#6

Take a look at DataParcel — An annotation processor to automatically generate Parcelable wrappers for Kotlin Data Classes.

[quote=Bradley Campbell]
For any of the Android developers in here, I’m hoping some of you are interested in my annotation processor that generates Parcelable wrapper classes for kotlin data classes. I’m looking for feedback, bugs, questions, or even pull requests. It’s not released yet officially so I’d appreciate it not being posted to Reddit unless there’s a disclaimer. [/quote]