Monday, July 9, 2018

Java what does a protected variable mean in enum type?




In Java 9, I can write code like this:




enum Abc {
A, B, C;
static protected int foo = 4; // what is the purpose of the protected variables like this in enum?
}


I think it makes no sense, because we cannot inherit or implement an enum.



Edit: This question is the same with Why are protected members allowed in final java classes?


Answer




It means just what it always means: accessible only from subclasses or classes in the same package. You're right that since you can't inherit the class, it's not any different from a package-private field in practice.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...