1

I need to invoke EnumSet#nonOf or EnumSet#allOf with an unknown type of class.

    @Override
    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
        final EnumSetOfAll annotation = parameterContext.getParameter().getAnnotation(EnumSetOfAll.class);
        final Class<?> value = annotation.value();
        if (!value.isEnum()) {
            throw new ParameterResolutionException("value(" + value + ") is not an enum");
        }

        // How can I return the result of EnumSet#(all|none)Of invoked with value?

    }

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184

1 Answers1

2

First, change the type of your annotation's value() to Class<? extends Enum>.

Now you can do:

final Class<? extends Enum> value = annotation.value();

Now this can be passed to allOf and noneOf:

EnumSet<?> set = EnumSet.allOf(value);
Sweeper
  • 213,210
  • 22
  • 193
  • 313