Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a java convention for packaging enums? [closed]

Tags:

Is there a Java convention for packaging enums? if not is there a best practice? Should I put them all in one package "myapp.enum" or should I put each enum in its related package?

like image 496
sabrina2020 Avatar asked Mar 25 '16 13:03

sabrina2020


People also ask

How do I package enums?

enum is a reserved keyword so you cannot put your enums into the enum package. Packages could be named after the layers of the application (Model, View, Controller, ..) You are free to choose. The only recommendation is to use unique package names like the reverse domain name of your company: mycompany.com -> com.

Do enums have to be capitalized Java?

Because they are constants, the names of an enum type's fields are in uppercase letters. You should use enum types any time you need to represent a fixed set of constants.

Which of the following is true about enum in Java?

An enum can, just like a class , have attributes and methods. The only difference is that enum constants are public , static and final (unchangeable - cannot be overridden). An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).

Do Java enums start at 0 or 1?

enum starts always with 0.


1 Answers

enums in Java should be treated like any other class, and should probably be placed in the package that's most related to them. There's no advantage in having a separate "enums" package.

like image 188
Mureinik Avatar answered Oct 12 '22 18:10

Mureinik