I have this kind of enum
public enum MyEnum {
member1(MyClass1.class){
@Override
public void doStuff(Object obj) {
...
}
},
member2(MyClass2.class){
@Override
public void doStuff(Object obj) {
...
}
};
...
public abstract void doStuff(Object obj);
}
What I would like to do is call the method in the enum like this:
MyEnum.member1.doStuff(myObject);
And have the methods in enum which object it has to cast to. Lets say the myObject that I pass in is MyClass1. The member1 should know automatically that it is only expecting MyClass1 which is also defined in the enum member description.
Is something like this even possible or I am walking a completely wrong path?