I'm trying to write an array of objects that implement Parcelable into a Parcel using writeParcelableArray.
The objects I'm trying to write are defined (as you'd expect) as:
public class Arrival implements Parcelable {
/* All the right stuff in here... this class compiles and acts fine. */
}
And I'm trying to write them into a `Parcel' with:
@Override
public void writeToParcel(Parcel dest, int flags) {
Arrival[] a;
/* some stuff to populate "a" */
dest.writeParcelableArray(a, 0);
}
When Eclipse tries to compile this I get the error:
Bound mismatch: The generic method writeParcelableArray(T[], int) of type Parcel is not applicable for the arguments (Arrival[], int). The inferred type Arrival is not a valid substitute for the bounded parameter < T extends Parcelable >
I completely don't understand this error message. Parcelable
is an interface (not a class) so you can't extend it. Anyone have any ideas?
UPDATE: I'm having basically the same problem when putting an ArrayList
of Parcelable
s into an Intent
:
Intent i = new Intent();
i.putParcelableArrayListExtra("locations", (ArrayList<Location>) locations);
yields:
The method putParcelableArrayListExtra(String, ArrayList< ? extends Parcelable >) in the type Intent is not applicable for the arguments (String, ArrayList< Location >)
This may be because Location
was the class I was working on above (that wraps the Arrival
s), but I don't think so.
Actually, you can extend an interface, and it looks like you need to do just that. The generics parameter in writeParcelableArray is asking for an extended interface (not the interface itself). Try creating an interface MyParcelable extends Parcelable. Then declaring your array using the interface, but the impl should be your Arrival extends MyParcelable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With