Hi all,
I have a pretty simple case where I do some basic generic assignment:
final Detail detail = field.getAnnotation(Detail.class);
final String example = detail.example();
final Class<?> type = field.getType();
if (List.class.isAssignableFrom(type))
...
else if (Enum.class.isAssignableFrom(type))
setValue(contract, field, Enum.valueOf(type, example));
else if (...)
.....
but the [Enum.valueOf()][1] is a bit difficult to call, in my case, the error is valueOf(java.lang.Class,java.lang.String) in java.lang.Enum cannot be applied to (java.lang.Class,java.lang.String)
This makes perfectly sense since type is Class. But since Enum is CRTP, I can't find a good way to cast type to make the compiler happy. Is using the raw type (Enum.valueOf((Class)type, example))) the only answer ? It gives me 2 warnings instead of only one.
Thanks for your help,
Nico.
[1]: http://www.j2ee.me/j2se/1.5.0/docs/api/java/lang/Enum.html#valueOf%28java.lang.Class, java.lang.String)