Parcelable, what is newArray for?

后端 未结 3 1870
深忆病人
深忆病人 2021-02-14 11:02

I am implementing Parcelable in order to transmit some simple data throughout an Intent.
However, There is one method in the Parcelable interface that I don\'t understand at

相关标签:
3条回答
  • 2021-02-14 11:33

    It is there to prepare the typed array without all the generics stuff. That's it.
    Returning just the standard return new MyParcelable[size]; is fine.

    It is normal, that you never call it yourself. However, by calling something like Bundle.getParcelableArray() you end up in this method indirectly.

    0 讨论(0)
  • 2021-02-14 11:35

    newArray is responsible to create an array of our type of the appropriate size

    0 讨论(0)
  • 2021-02-14 11:38

    this is a function to be called when you try to deserialize an array of Parcelable objects and for each single object createFromParcel is called.

    0 讨论(0)
提交回复
热议问题