Since an enum constructor can only be invoked by its constants, why is it then allowed to be package-private?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The constructor actually isn't package-private... it's implicitly
private
the way interface methods are implicitlypublic
even if you don't add the keyword.The relevant section of the JLS (§8.8.3) states:
It's a quirk of the language: enum constructors are implicitly private.
Interestingly, if you declare a package-visible enum constructor, like this:
you can't refer to it from another class in the package. If you try, you get the compiler error: