alex
alex

Reputation: 3442

Java generics: is this a covariance issue?

I have a class like this:

public class MyClass<T>{
    private MyTape data;
    private List<T> someOtherdata;
}

I'm trying to write a generic service in Android usign Spring for Android RestTemplate, but this give a type mismatch:

ResponseEntity<MyClass<? extends Parcelable>> test = new ResponseEntity<MyClass<MyOtherType>>(..);

Where MyOtherType implements Parcelable. In there a way around this? My other solution is to use "less generic code" and subclass MyClass

Upvotes: 2

Views: 159

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198211

Use

 ResponseEntity<? extends MyClass<? extends Parcelable>>

instead of

 ResponseEntity<MyClass<? extends Parcelable>>

Upvotes: 4

Related Questions