public enum FOO{
TATA(TOTO,TITI);
public FOO(BAR bar1,BAR bar2) {
bar1.associate(this,bar2);
}
}
public enum BAR {
TOTO,
TITI;
private FOO _foo;
private BAR _bar;
public void associate(FOO foo,BAR bar) {
_foo = foo;
_bar = bar;
}
}
The problem was that in my code I called BAR before FOO. The result was the fields in BAR were null. I finally found out why. (enum are only instantiated when they are called for the first time). To fix this problem I added FOO.TATA; before I use Bar in a specific file.
So my question, Is there a more elegant way to make sure one enum is instantiate before another?