KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
class HasId<I> {} class HasStringId extends HasId<String> {} class Alert<T extends /*Some*/Object> extends HasStringId {} class BaseController<M extends HasId<String>> { // abstract Class<M> getModelClass(); } class AlertController extends BaseController<Alert> { // error here // @Override Class<Alert> getModelClass() { // return Alert.class; // } } compiles fine on OpenJDK6, but in OpenJDK7 gives: AlertController.java:50: error: type argument Alert is not within bounds of type-variable T class AlertController extends BaseController<Alert> { ^ where T is a type-variable: T extends HasId<String> declared in class BaseController Note that there's rawtype warning at line 50, because Alert must be parameterized. If I do that, e.g. extends BaseController<Alert<Object>> , code compiles. But I cannot do that, because I need to implement getModelClass(). UPDATE: That was a bug in Java 6 implementations, which was fixed in Java 7: https://bugs.java.com/bugdatabase/view_bug?bug_id=6559182 . (And here's my question to compiler devs: http://openjdk.5641.n7.nabble.com/Nested-generics-don-t-compile-in-1-7-0-15-but-do-in-1-6-0-27-td121820.html )
Tags (comma-separated)
Save Edits
Cancel