Q:

How to get an enum constant from the first matching enum type

Note: this question is more about generics than it is about enums.
I have few enum types, all implementing a common interface IEffect. 
For example
enum ElementalEffect implements IEffect {
    FIRE, WATER;
}
enum CombatEffect implements IEffect {
    PARALYSIS, SLEEP;
}

I would like to parse a config-file, that should add effects to a weapon. For that I have to resolve a given name to one of the effects. To keep it simple to maintain, I thought of writing a method like this (mostly pseudo-code, this does not compile. In fact the point of the question is how to make this compile):
IEffect resolveEffectName(String name, Class... clazzes) {
    for(Class clazz : clazzes) {
        try {
            return Enum.valueOf(clazz, name);
        } catch(IllegalArgumentException) { /* ignore, try next class */}
    }
    throw new IllegalArgumentException("No matching effect found for " + name);
}
// resolveEffectName(readNameFromFile, ElementalEffect.class, CombatEffect.class);

Now the problem I have is that I can't figure out how to write that method without the compiler telling me

The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments ...

People saying it should be
private static ICombatEffectType getFirstResolved(String name, Class<? extends Enum<?>>... classes) {
    for (Class<? extends Enum<?>> clazz : classes) {
        try {
            return Enum.valueOf(clazz, name);
        } catch (IllegalArgumentException e) {
        }
    }
    return null;
}

This is not working. Feel free to try it (if you don't believe me).

The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments (Class<capture#6-of ? extends Enum<?>>, String)

A:

You can write this fluently, if that's your style:
class FluentGetter {
  private final String name;
  private IEffect found;

  FluentGetter(String name) { this.name = name; }

  <T extends Enum<T> & IEffect> FluentGetter search(Class<T> clazz) {
    if (found == null) { // If you've already found something, don't overwrite that.
      try {
        found = Enum.valueOf(clazz, name);
      } catch (IllegalArgumentException e) {}
    }
    return this;
  }

  IEffect get() {
    return found;  // + check if it's null, if you want.
  }
}

Then:
IEffect effect =
    new FluentGetter(name)
        .search(ElementalEffect.class)
        .search(CombatEffect.class)
        .get();

This avoids the problem of the generic bounds on the array of classes by having separate method calls for each.
Pretty sure I wouldn't use this myself; just tossing it out as an option.

