<div dir="auto">I recently tinkered a bit with java enums. While I was researching edge features enums support I came across a stackoverflow post referencing the JLS 8.9 saying that the optional body of an enum constant is an anonymous class declaration. <div dir="auto">As for some time now methods declared in an anonymous class assigned to a var variable are accessible I tried to do the same for the enum constant. </div><div dir="auto"><br></div><div dir="auto">var anonymous = new Object() {</div><div dir="auto"><span style="white-space:pre"> </span>public void test() {} </div><div dir="auto">}</div><div dir="auto">anonymous.test(); //works</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">enum Test {</div><div dir="auto"><span style="white-space:pre">     </span>A {</div><div dir="auto"><span style="white-space:pre">              </span>public void test() {} </div><div dir="auto"><span style="white-space:pre">  </span>} </div><div dir="auto">}</div><div dir="auto">var enumConstant = Test.A;</div><div dir="auto">enumConstant.test(); // doesn't work</div><div dir="auto"><br></div><div dir="auto">I have a clue to why this doesn't work. It's likely that the type of the constant A is the type of the enum and not of the anonymous class. </div><div dir="auto"><br></div><div dir="auto">There are some usecases where exclusive methods on enum constants might be useful. So it would be nice if this would work. </div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div></div>