Nested generics don't compile in 1.7.0_15, but do in 1.6.0_27.

Dzmitry Lazerka dlazerka at gmail.com
Sun Mar 10 20:25:45 PDT 2013


Hi,

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:

Controller.java:50: error: type argument Alert is not within bounds of
    type-variable T
class Controller 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().

Ubuntu 12.04.

Is it a bug in 1.7.0_15? Can you suggest any workarounds?

-----
Best regards,
Dzmitry Lazerka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20130310/4707f4c8/attachment.html 


More information about the compiler-dev mailing list