Open jja725 opened 2 years ago
If I see this correctly, because of type erasure it does not actually know the type of the enum (or the fact that it is an enum) once the code is compiled. Meaning what it actually is after compilation is public Object mOperation;
What you could try in your OperationConverter
if (clazz.isEnum()) // probably good to check to ensure it is an enum and throw an exception if not. You should get some safety with your initial approach with `T extends Enum<T>` though.
for (S element : clazz.getEnumConstants()) {
if (value.equals(element.name())
...
}
but I am not sure what you would get provided to this constructor protected OperationConverter(Class<S> clazz)
, I would think that JCommander requires an empty constructor to create an instance. Again, JCommander would not know what type the enum is supposed to be due to type erasure.
I try to create an abstract class with some common parameters so I can inherit from this class and create several similar parameters. But I'm struggling with the Jcommander with Enum types. The following code giving me the error. I'm wondering if no converter is specified for an enum type, does EnumConverter gets called?
I search online and try to add converter but doesn't know how to do so. (Need an interface for Enum with common fromString method)
Does anyone have any idea how to make it work?