When you call the method with an EnumSet<SomeType>
the identity of SomeType
undergoes erasure and is not known. You need to accept an instance of SomeType
or Class<SomeType>
to avoid erasure:
private void doSomethingA(EnumSet<TypeA>){ ... }
private void doSomethingA(EnumSet<TypeA>){ ... }
private void <T extends Enum<T>> doSomething(EnumSet<T extends BaseType> s, T tInst){
if(t instanceof TypeA) doSomethingA(s);
if(t instanceof TypeB) doSomethingB(s);
}
For readability, I use T
and t
but it could be written as:
private void <SOMETYPE extends Enum<SOMETYPE>> doSomething(EnumSet<SOMETYPE> s, SOMETYPE instanceOfSomeType){
if(instanceOfThatType instanceof TypeA) doSomethingA(s);
if(instanceOfThatType instanceof TypeB) doSomethingB(s);
}
Note that SOMETYPE
and T
are written as-is. They are placeholders at runtime, but literal at the time of writing the code.