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