views:

669

answers:

2
enum MyEnum {
  A( 1, 2, 3, 4),
  B(1, 2),
  C(4, 5, 8, 8, 9);

 private MyEnum( int firstInt, int... otherInts ) {
  // do something with arguments, perhaps initialize a List
 }
}

Are there any problems with this? Any reasons not to do it?

+3  A: 

Sure, this is perfectly legal. No reason not to do it if your program requires it.

Jorn
i seem to be getting some weird class initialization errors when i tried this ... so i removed the var args and it worked. (note the the program compiled cleanly both ways).probably did something i didn't notice ... oh well, the solution i came up with in the end is better (i think).
LES2
Just out of curiosity ... could you print the error message? I cannot see any reason at all this shouldn't work. In fact, I copy/pasted your code and it compiled and ran right out of the box.
Pål GD
A: 

it does work. You should try to

private MyEnum(int... Ints )

With enums you need to make sure that you access them in a manner the initializes them. A lot of the time an access is all that is needed

MyEnum bob = MyEnum.A;
Milhous