Java - Inheriting from a class that accepts generics? [closed]
How do you inherit from this class? The following code is broken but it shows what I'm trying to achieve.
Bound Mismatch: The type T is not a valid substitude for the bounded parameter of the type ActivityInstrumentationTestCase2
public class MyClass<T> extends ActivityInstrumentationTestCase2<T> {
public MyClass (Class<T> cl开发者_如何学Goazz) {
super(clazz);
}
}
What is the class definition of ActivityInstrumentationTestCase2?
Most likely, ActivityInstrumentationTestCase2 is defined as:
class ActivityInstrumentationTestCase2<T extends SomeObject> {
...
}
In which case, your object's parameters needs to stay within its superclass's parameters.
For example:
public class MyObject<T extends SomeObject> extends ActivityInstrumentationTestCase2<T> {
...
}
You could also make the parameter narrower. So, if MySomeObject extended SomeObject you could also say:
public class MyObject<T extends MySomeObject> extends ActivityInstrumentationTestCase2<T> {
...
}
Edit to add: I just found this. I assume you're using the same one, so it needs to be defined as:
public class MyObject<T extends android.app.Activity> extends ActivityInstrumentationTestCase2<T> {
...
}
精彩评论