You can't do what you just tried. There are several options though as to how. None of them will probably be what you want, but it's the way that they work. Especially if you want to include the 'final' functionality.

Best way around it? Create an initializer method that you call where-ever other things get initialized to set up these relations. Then get them through a method (Which causes these variables to act as final for this purpose, since an enum cannot be extended.)

I am guessing that the problem comes from the fact that the method you are calling assumes to have a reference to all the other enum constants. Since it's used in the constructor, the references it needs do not exist yet.

Here is one alternative. You could also use a switch statement with enum consant values or an enum map.

You can use a static initializer to keep the entire definition within the enum and retrieve without having to recalculate anything each time. I made toLeft and toRight private and added accessor methods. They are no longer final but you can't change the values any how.

is simpler in that you don't have to care about the order the Enum values are defined in and you don't have to do calculations, array lookups, or retrieving ordinal positions to get what can be defined simply once and for all. The downside is storing 3 enum values for each enum which in this case is nothing. If the Enum had a lot more values (N,NNE,NE,ENE,E, etc..) or had a lot more relationships to track then the more compact code would look more attractive.

Quote

I've never been a fan of the static code chunk, if only because it's hard to tell when it gets executed. For this, I figure it's not too much of a problem, but I tend to not suggest it. xD

I got the static initializer idea from a stack overflow post. I was originally thinking along your lines but what I like about this is that the definition is complete within itself. You don't have to remember to call a method from some where else. Then again, I tend to use statics more often than other Java programmers I've worked with.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org