[type-annos-observers] error: enclosing static nested class cannot be annotated ??

Srikanth S Adayapalam srikanth_sankaran at in.ibm.com
Mon Oct 7 20:12:04 PDT 2013


I'll let this discussion take its course to see where it leads. In the 
meantime here are
some other examples that show the reference compiler (8b108) behaving 
inconsistently.
This is admittedly not the place to report RI issues, but to the extent 
they are pertinent
to the discussion at hand, they should be useful: 
Thanks,
Srikanth

1.  I would expect two errors here, but get only one:

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target(ElementType.TYPE_USE)
@interface Illegal {
}
class Y {
                 static class Z {
                                 Z() {}
                 }
}
class X {
                 Y.Z foo() {
                                 @Illegal Y.Z z = null;
                                 return z;
                 }
                 Y.Z bar() {
                                 Y.Z z = (@Illegal Y.Z)null;   // No error 
here ??
                                 return z;
                 }
}

2. I would not expect an error at annotation site of @LegalTypeUseParam: I 
would expect
that the TYPE_USE target to be silently discarded and the PARAMETER target 
to be honored.
This is by intuition, not sure if the spec sanctions such.

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target(ElementType.TYPE_USE)
@interface IllegalTypeUse {
}
@Target({ElementType.TYPE_USE, ElementType.PARAMETER})
@interface LegalTypeUseParam {
}
@Target(ElementType.PARAMETER)
@interface LegalParam {
}
class Y {
                 static class Z {
                                 Z() {}
                 }
}
class X {
                 Y.Z foo(@LegalParam Y.Z z) { //Legal
                                 return z;
                 }
                 Y.Z foo2(@LegalTypeUseParam Y.Z z) { //Legal
                                 return z;
                 }
                 Y.Z foo3(@IllegalTypeUse @LegalParam Y.Z z) { //Illegal
                                 return z;
                 }
}


More information about the type-annotations-spec-observers mailing list