Reputation: 33297
I have an interface
public interface BWidgetObject<T> {
}
and I want to use this interface to create a new generic interface based on this type:
public interface BDataList<BWidgetObject> {}
The former gives a warning that the type T
is hidden. The following give a compiler error:
public interface BDataList<BWidgetObject<T>> {}
How can I express BWidgetObject<T>
as type parameter for BDataList
?
Upvotes: 5
Views: 79
Reputation: 62864
You can try with:
public interface BDataList<T extends BWidgetObject<?>> {}
Here we're specifying the the type T
will be a BWidgetObject
of a type we don't actually care about (and that's why we use a wildcard). We only care about T
and the fact it will be a subtype of BWidgetObject
.
Upvotes: 6
Reputation: 425033
Use a generic bound:
public interface BDataList<T extends BWidgetObject<?>> {}
Or if you need to type the widget explicitly, you need to create another sub-interface:
public interface BWidgetDataList<T> extends BDataList<BWidgetObject<T>> {}
Upvotes: 1