One Enum per File?

J

Joan

Since an Enum is a class, is it expected that
you put only one Enum in a file? This could
make for a whole lot of files for some applications.
 
R

Roedy Green

Since an Enum is a class, is it expected that
you put only one Enum in a file? This could
make for a whole lot of files for some applications.

One file per enum usually works out best. If the enum is not public,
you can make it a top level non-nested class with package visibility

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
J

Jim McMaster

Since an Enum is a class, is it expected that
you put only one Enum in a file? This could
make for a whole lot of files for some applications.

The enum defines the structure of the enum type, and also the
definitions of all the member types of the enum. You can have:

public enum MyEnum {
MyType1, MyType2, MyType3
}

to define an enum with three types.
 
D

Dale King

Roedy said:
One file per enum usually works out best. If the enum is not public,
you can make it a top level non-nested class with package visibility

I would say that it would probably be rare that you want a top-level
enum. Usually the enum is going to be associated with some API and
defined in that class or intreface.

I've actually defined an enum nested within another enum.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top