Java annotation cannot access protected static fields from upper class

后端 未结 4 751
逝去的感伤
逝去的感伤 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:26

    This code will compile only if both A and B belong to the same package.

提交回复
热议问题