From another question I have learnt that it is possible in Java to define specific methods for each one of the instances of an Enum:
public class AClass {
private enum MyEnum{
A { public String method1(){ return null; } },
B { public Object method2(String s){ return null; } },
C { public void method3(){ return null; } } ;
}
...
}
I was surprised that this is even possible, do this "exclusive methods" specific to each instance have a name to look for documentation?
Also, how is it supposed to be used? Because the next is not compiling:
private void myMethod () {
MyEnum.A.method1();
}
How am I supposed to use these "exclusive" methods?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…