9

I'm using kotlin android extensions to auto generate my Parcelables, but given the following code I'm getting 'Parcelable' should be a class.

the code:

sealed class Action : Parcelable

@Parcelize
object Run : Action()

@Parcelize
data class Ask(
    val question: String
) : Action()

My understanding is that it is impossible to use @Parcelize in an object (Once it is working on the Ask class) in the way I'm doing it.

I want to use the Parcelable annotation in an object that extends a sealed class, so I'm do not know how to do it and do not write the following boilerplate.

object Run : Action() {

    override fun writeToParcel(p0: Parcel?, p1: Int) {}
    override fun describeContents() = 0

    @JvmField
    val CREATOR = object : Parcelable.Creator<Run> {
        override fun createFromParcel(parcel: Parcel) = Run
        override fun newArray(size: Int) = arrayOfNulls<Run?>(size)
    }

}
ademar111190
  • 14,215
  • 14
  • 85
  • 114

1 Answers1

9

You need to make sure that you have you Kotlin up to date.

You can follow an example here.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140