Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Difference between private and package-private enum constructor [duplicate]

Recently I'm quite oftenly using Enumerations. So I wonder...

Is there any difference between a private Enum constructor and a enum constructor withour any visibility modifier (package-private)?

like image 830
MinecraftShamrock Avatar asked Nov 17 '25 17:11

MinecraftShamrock


1 Answers

The constructor for enums is implicitly private, just like methods for interfaces and annotations are implicitly public abstract. The default is package local for class members.

BTW enum classes are implicitly final and nested enum classes are implicitly static.

Older constructs tend to allow you to add implicit modifiers, but newer constructs don't allow you to say. e.g. enums are final but you can't add final to an enum.

like image 131
Peter Lawrey Avatar answered Nov 20 '25 05:11

Peter Lawrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!