8 Replies Latest reply: Apr 4, 2013 2:13 PM by TPD-Opitz RSS

    Declaring Argument as Class of Enum That Implements Interface

      I'm trying to declare a method parameter that is the class of an enum which implements a specified interface. I can't figure out the required syntax, or if this is even possible.

      Here is the interface:
      public interface Describer { String describe(); }

      Here' s an enum that implements the interface:
      public enum DeviceProperty implements Describer {
      TYPE("Device Type"),
      USE("Device Use");
      private String description;
      private DeviceProperty(final String description) { this.description = description; }
      @Override public String describe() { return description; }

      Here's my unsuccessful attempt to declare the method parameter:
      public <E extends Enum<E extends Describer>> void addChanges(final Class<E> properties) {
           final EnumSet<E> set = EnumSet.allOf(properties);
           for (final Enum<E> property : set) {
                // Do something with the property

      The problem, of course, is that addChanges() doesn't compile. If I remove "extends Describer" it compiles, but then I can't detect compile time errors (i.e., an enum which doesn't implement Describer).

      Is what I'm attempting even possible in Java? If so, I'd be very grateful if someone could explain the correct syntax.