Originally posted by John Bartlett:
Hi,
I was wondering whether it is possible to nest enums?
My problem is that I want an enum called country and then I want a nested enum within that called state/province, is this possible?
so you could do a call maybe something like this:
State state = Country.US.State.NY;
Thanks in advance,
John
Not in the way you want. Realize that your Country enum is a full-fledged class, 1.5 just provides some syntactic sugar to do what we've been doing for a decade. If you were to declare a State enum nested within Country then that would be a nested class like any other. Country.US.State.NY is probably syntactically possible, but it would mean that Country.CANADA.State.NY was just as valid. US and CANADA are both a Country, and State would just be an (implicitly) static nested class of Country.
Perhaps
you should describe the "big picture" and we might have some better design suggestions for your problem.