Java annotation cannot access protected static fields from upper class

后端 未结 4 740
逝去的感伤
逝去的感伤 2021-01-20 00:00

Is this code valid?

public abstract class A {
   protected static final String c = \"my const\";
}

@myAnnotation(value=A.c)
public class B extends A {

}
         


        
4条回答
  •  庸人自扰
    2021-01-20 00:33

    The Annotation you are trying to fill with the "const" tries to access the class from outside by using protected that can't work. Eclipse uses it's own compiler so you should try to make clean rebuild in Eclipse to see if it's working. I assume it will not.

提交回复
热议问题