Adding "private" to enum field changes static context
This question already has an answer here:
Try this
((TestEnum)this).x
The error message is a misleading. The problem is, private
field is not inherited, therefore x
or this.x
won't compile. You have to up-cast it to the superclass to access it.
see also https://groups.google.com/d/msg/java-lang-fans/KVmmgeSCHkA/Kr_KxaaeolIJ
The 'protected' access is probably better here
protected int x;
链接地址: http://www.djcxy.com/p/38074.html
上一篇: 在构造函数之外访问枚举参数?