I basically want to have an enum with specific methods, e.g.
public interface PropertyTypeMethods {
public int getTypeId();
public void setTypeId(Integer typeId);
}
and something like
public enum BasePropertyTypes implements PropertyTypeMethods {
ONE, TWO;
private int typeId;
@Override
public int getTypeId() {
return typeId;
}
@Override
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
}
as well as an extended version of this enum, e.g.
public enum ExtendedPropertyTypes implements PropertyTypeMethods {
HUNDRED, THOUSEND;
// same as above
}
which would result in ONE.setTypeId(1) ==> ONE.getTypeId()==1 //true. That is the basic concept. But now I want to call a generic method like e.g.
private <E extends Enum<E> & PropertyTypeMethods> void initEnum(Enum<E> curType) {
// the below approach does not work :-/
curType.setTypeId(1); // or any other reasonable value....
But somehow I cannot figure out what the correct method signature would be. Following this question I figured at least some part of the puzzle -
but still don't get it for the method signature. Still it remains unclear how to specify curType properly in the signature to execute an appropriate call.
<E extends Enum<E> & PropertyTypeMethodes>? To set the type,<E extends PropertyTypeMethods>is enough.privateorprotectedconstructor and add constant instances. Voila, it's basically an mutable and extendable enum. You may also add astaticmethod to provide all available instances of that class likevalues()on enums.