开发者

Java - Inheriting from a class that accepts generics? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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> {
...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜