为什么枚举要实现接口?

发布于 2024-08-30 01:43:52 字数 36 浏览 9 评论 0原文

我刚刚发现Java允许枚举来实现接口。什么是一个好的用例?

I just found out that Java allows enums to implement an interface. What would be a good use case for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

少女情怀诗 2024-09-06 01:43:52

下面是一个示例(在《Effective Java 第二版》中找到了类似/更好的示例):

public interface Operator {
    int apply (int a, int b);
}

public enum SimpleOperators implements Operator {
    PLUS { 
        int apply(int a, int b) { return a + b; }
    },
    MINUS { 
        int apply(int a, int b) { return a - b; }
    };
}

public enum ComplexOperators implements Operator {
    // can't think of an example right now :-/
}

现在获取简单 + 复杂运算符的列表:

List<Operator> operators = new ArrayList<Operator>();

operators.addAll(Arrays.asList(SimpleOperators.values()));
operators.addAll(Arrays.asList(ComplexOperators.values()));

因此,这里使用一个接口来模拟可扩展枚举(如果不使用,这是不可能的)一个接口)。

Here's one example (a similar/better one is found in Effective Java 2nd Edition):

public interface Operator {
    int apply (int a, int b);
}

public enum SimpleOperators implements Operator {
    PLUS { 
        int apply(int a, int b) { return a + b; }
    },
    MINUS { 
        int apply(int a, int b) { return a - b; }
    };
}

public enum ComplexOperators implements Operator {
    // can't think of an example right now :-/
}

Now to get a list of both the Simple + Complex Operators:

List<Operator> operators = new ArrayList<Operator>();

operators.addAll(Arrays.asList(SimpleOperators.values()));
operators.addAll(Arrays.asList(ComplexOperators.values()));

So here you use an interface to simulate extensible enums (which wouldn't be possible without using an interface).

羁拥 2024-09-06 01:43:52

枚举不仅仅必须表示被动集(例如颜色)。它们可以表示具有功能的更复杂的对象,因此您可能希望向这些对象添加更多功能 - 例如,您可能拥有诸如 PrintableReportable 等接口以及支持这些的组件。

Enums don't just have to represent passive sets (e.g. colours). They can represent more complex objects with functionality, and so you're then likely to want to add further functionality to these - e.g. you may have interfaces such as Printable, Reportable etc. and components that support these.

凝望流年 2024-09-06 01:43:52

这里几个人给出的 Comparable 示例是错误的,因为 Enum 已经实现了它。你甚至无法覆盖它。

一个更好的例子是拥有一个定义数据类型的接口。您可以使用枚举来实现简单类型,并使用普通类来实现复杂类型:

interface DataType {
  // methods here
}

enum SimpleDataType implements DataType {
  INTEGER, STRING;

  // implement methods
}

class IdentifierDataType implements DataType {
  // implement interface and maybe add more specific methods
}

The Comparable example given by several people here is wrong, since Enum already implements that. You can't even override it.

A better example is having an interface that defines, let's say, a data type. You can have an enum to implement the simple types, and have normal classes to implement complicated types:

interface DataType {
  // methods here
}

enum SimpleDataType implements DataType {
  INTEGER, STRING;

  // implement methods
}

class IdentifierDataType implements DataType {
  // implement interface and maybe add more specific methods
}
孤君无依 2024-09-06 01:43:52

有一个我经常使用的案例。我有一个带有静态方法的 IdUtil 类,用于处理实现非常简单的 Identifying 接口的对象:

public interface Identifiable<K> {
    K getId();
}


public abstract class IdUtil {

    public static <T extends Enum<T> & Identifiable<S>, S> T get(Class<T> type, S id) {
        for (T t : type.getEnumConstants()) {
            if (Util.equals(t.getId(), id)) {
                return t;
            }
        }
        return null;
    }

    public static <T extends Enum<T> & Identifiable<S>, S extends Comparable<? super S>> List<T> getLower(T en) {
        List<T> list = new ArrayList<>();
        for (T t : en.getDeclaringClass().getEnumConstants()) {
             if (t.getId().compareTo(en.getId()) < 0) {
                 list.add(t);
            }
        }
        return list;
    }
}

如果我创建一个 Identifying enum< /code>:

    public enum MyEnum implements Identifiable<Integer> {

        FIRST(1), SECOND(2);

        private int id;

        private MyEnum(int id) {
            this.id = id;
        }

        public Integer getId() {
            return id;
        }

    }

然后我可以通过它的 id 来获取它:

MyEnum e = IdUtil.get(MyEnum.class, 1);

There is a case I often use. I have a IdUtil class with static methods to work with objects implementing a very simple Identifiable interface:

public interface Identifiable<K> {
    K getId();
}


public abstract class IdUtil {

    public static <T extends Enum<T> & Identifiable<S>, S> T get(Class<T> type, S id) {
        for (T t : type.getEnumConstants()) {
            if (Util.equals(t.getId(), id)) {
                return t;
            }
        }
        return null;
    }

    public static <T extends Enum<T> & Identifiable<S>, S extends Comparable<? super S>> List<T> getLower(T en) {
        List<T> list = new ArrayList<>();
        for (T t : en.getDeclaringClass().getEnumConstants()) {
             if (t.getId().compareTo(en.getId()) < 0) {
                 list.add(t);
            }
        }
        return list;
    }
}

If I create an Identifiable enum:

    public enum MyEnum implements Identifiable<Integer> {

        FIRST(1), SECOND(2);

        private int id;

        private MyEnum(int id) {
            this.id = id;
        }

        public Integer getId() {
            return id;
        }

    }

Then I can get it by its id this way:

MyEnum e = IdUtil.get(MyEnum.class, 1);
白鸥掠海 2024-09-06 01:43:52

由于枚举可以实现接口,因此它们可以用于严格执行单例模式。尝试使标准类成为单例允许...

  • 使用反射技术将私有方法公开为公共方法,
  • 以便从单例继承并用其他枚举覆盖单例的方法,因为

单例有助于防止这些安全问题。这可能是让枚举充当类并实现接口的原因之一。只是一个猜测。

请参阅 https:// stackoverflow.com/questions/427902/java-enum-singletonjava 中的 Singleton 类 进行更多讨论。

Since Enums can implement interfaces they can be used for strict enforcing of the singleton pattern. Trying to make a standard class a singleton allows...

  • for the possibility of using reflection techniques to expose private methods as public
  • for inheriting from your singleton and overriding your singleton's methods with something else

Enums as singletons help to prevent these security issues. This might have been one of the contributing reasons to let Enums act as classes and implement interfaces. Just a guess.

See https://stackoverflow.com/questions/427902/java-enum-singleton and Singleton class in java for more discussion.

妄司 2024-09-06 01:43:52

它是可扩展性所必需的——如果有人使用您开发的 API,您定义的枚举是静态的;无法添加或修改它们。但是,如果让它实现一个接口,那么使用该 API 的人就可以使用相同的接口开发自己的枚举。然后,您可以使用枚举管理器注册该枚举,该管理器将枚举与标准接口组合在一起。

编辑:@Helper Method 有一个完美的例子。考虑让其他库定义新的运算符,然后告诉管理器类“嘿,这个枚举存在 - 注册它”。否则,您只能在自己的代码中定义运算符 - 没有可扩展性。

It's required for extensibility -- if someone uses an API you've developed, the enums you define are static; they can't be added to or modified. However, if you let it implement an interface, the person using the API can develop their own enum using the same interface. You can then register this enum with an enum manager which conglomerates the enums together with the standard interface.

Edit: @Helper Method has the perfect example of this. Think about having other libraries defining new operators and then telling a manager class that 'hey, this enum exists -- register it'. Otherwise, you'd only be able to define Operators in your own code - there'd be no extensibility.

带上头具痛哭 2024-09-06 01:43:52

上面提到的策略的帖子没有充分强调使用枚举的策略模式的轻量级实现可以给您带来什么:

public enum Strategy {

  A {
    @Override
    void execute() {
      System.out.print("Executing strategy A");
    }
  },
  
  B {
    @Override
    void execute() {
      System.out.print("Executing strategy B");
    }
  };

  abstract void execute();
}

您可以将所有策略放在一个位置,而不需要为每个策略提供单独的编译单元。您只需执行以下操作即可获得良好的动态调度:

Strategy.valueOf("A").execute();

使 java 读起来几乎像一种美味的松散类型语言!

The post above that mentioned strategies didn't stress enough what a nice lightweight implementation of the strategy pattern using enums gets you:

public enum Strategy {

  A {
    @Override
    void execute() {
      System.out.print("Executing strategy A");
    }
  },
  
  B {
    @Override
    void execute() {
      System.out.print("Executing strategy B");
    }
  };

  abstract void execute();
}

You can have all your strategies in one place without needing a separate compilation unit for each. You get a nice dynamic dispatch with just:

Strategy.valueOf("A").execute();

Makes java read almost like a tasty loosely typed language!

自此以后,行同陌路 2024-09-06 01:43:52

枚举只是伪装的类,因此在大多数情况下,您可以使用类执行的任何操作都可以使用枚举执行。

我想不出枚举不应该实现接口的原因,同时我也想不出他们这样做的充分理由。

我想说,一旦你开始向枚举添加接口或方法之类的东西,你真的应该考虑将其变成一个类。当然,我确信有做非传统枚举事情的有效案例,并且由于限制是人为的,所以我赞成让人们在那里做他们想做的事情。

Enums are just classes in disguise, so for the most part, anything you can do with a class you can do with an enum.

I cannot think of a reason that an enum should not be able to implement an interface, at the same time I cannot think of a good reason for them to either.

I would say once you start adding thing like interfaces, or method to an enum you should really consider making it a class instead. Of course I am sure there are valid cases for doing non-traditional enum things, and since the limit would be an artificial one, I am in favour of letting people do what they want there.

反差帅 2024-09-06 01:43:52

最常见的用法是将两个枚举的值合并为一组并以类似方式对待它们。例如,请参阅如何加入 Fruits和蔬菜

Most common usage for this would be to merge the values of two enums into one group and treat them similarly. For example, see how to join Fruits and Vegatables.

寒尘 2024-09-06 01:43:52

例如,如果您有一个 Logger 枚举。那么你的界面中应该有 debug、info、warning 和 error 等记录器方法。它使您的代码松散耦合。

For example if you have a Logger enum. Then you should have the logger methods such as debug, info, warning and error in the interface. It makes your code loosely coupled.

乖乖哒 2024-09-06 01:43:52

对我来说,将枚举与接口结合使用的最佳用例之一是谓词过滤器。这是弥补 apache 集合类型缺乏的非常优雅的方法(如果不能使用其他库)。

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;


public class Test {
    public final static String DEFAULT_COMPONENT = "Default";

    enum FilterTest implements Predicate {
        Active(false) {
            @Override
            boolean eval(Test test) {
                return test.active;
            }
        },
        DefaultComponent(true) {
            @Override
            boolean eval(Test test) {
                return DEFAULT_COMPONENT.equals(test.component);
            }
        }

        ;

        private boolean defaultValue;

        private FilterTest(boolean defautValue) {
            this.defaultValue = defautValue;
        }

        abstract boolean eval(Test test);

        public boolean evaluate(Object o) {
            if (o instanceof Test) {
                return eval((Test)o);
            }
            return defaultValue;
        }

    }

    private boolean active = true;
    private String component = DEFAULT_COMPONENT;

    public static void main(String[] args) {
        Collection<Test> tests = new ArrayList<Test>();
        tests.add(new Test());

        CollectionUtils.filter(tests, FilterTest.Active);
    }
}

One of the best use case for me to use enum's with interface is Predicate filters. It's very elegant way to remedy lack of typness of apache collections (If other libraries mayn't be used).

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;


public class Test {
    public final static String DEFAULT_COMPONENT = "Default";

    enum FilterTest implements Predicate {
        Active(false) {
            @Override
            boolean eval(Test test) {
                return test.active;
            }
        },
        DefaultComponent(true) {
            @Override
            boolean eval(Test test) {
                return DEFAULT_COMPONENT.equals(test.component);
            }
        }

        ;

        private boolean defaultValue;

        private FilterTest(boolean defautValue) {
            this.defaultValue = defautValue;
        }

        abstract boolean eval(Test test);

        public boolean evaluate(Object o) {
            if (o instanceof Test) {
                return eval((Test)o);
            }
            return defaultValue;
        }

    }

    private boolean active = true;
    private String component = DEFAULT_COMPONENT;

    public static void main(String[] args) {
        Collection<Test> tests = new ArrayList<Test>();
        tests.add(new Test());

        CollectionUtils.filter(tests, FilterTest.Active);
    }
}
风柔一江水 2024-09-06 01:43:52

在 jar 文件中创建常量时,让用户扩展枚举值通常很有帮助。我们使用枚举作为 PropertyFile 键并陷入困境,因为没有人可以添加任何新的!下面的效果会好得多。

给定:

public interface Color {
  String fetchName();
}

并且:

public class MarkTest {

  public static void main(String[] args) {
    MarkTest.showColor(Colors.BLUE);
    MarkTest.showColor(MyColors.BROWN);
  }

  private static void showColor(Color c) {
    System.out.println(c.fetchName());
  }
}

罐子中可以有一个枚举:

public enum Colors implements Color {
  BLUE, RED, GREEN;
  @Override
  public String fetchName() {
    return this.name();
  }
}

并且用户可以扩展它以添加自己的颜色:

public enum MyColors implements Color {
  BROWN, GREEN, YELLOW;
  @Override
  public String fetchName() {
    return this.name();
  }
}

When creating constants in a jar file, it is often helpful to let users extend enum values. We used enums for PropertyFile keys and got stuck because nobody could add any new ones! Below would have worked much better.

Given:

public interface Color {
  String fetchName();
}

and:

public class MarkTest {

  public static void main(String[] args) {
    MarkTest.showColor(Colors.BLUE);
    MarkTest.showColor(MyColors.BROWN);
  }

  private static void showColor(Color c) {
    System.out.println(c.fetchName());
  }
}

one could have one enum in the jar:

public enum Colors implements Color {
  BLUE, RED, GREEN;
  @Override
  public String fetchName() {
    return this.name();
  }
}

and a user could extend it to add his own colors:

public enum MyColors implements Color {
  BROWN, GREEN, YELLOW;
  @Override
  public String fetchName() {
    return this.name();
  }
}
赴月观长安 2024-09-06 01:43:52

另一种可能性:

public enum ConditionsToBeSatisfied implements Predicate<Number> {
    IS_NOT_NULL(Objects::nonNull, "Item is null"),
    IS_NOT_AN_INTEGER(item -> item instanceof Integer, "Item is not an integer"),
    IS_POSITIVE(item -> item instanceof Integer && (Integer) item > 0, "Item is negative");

    private final Predicate<Number> predicate;
    private final String notSatisfiedLogMessage;

    ConditionsToBeSatisfied(final Predicate<Number> predicate, final String notSatisfiedLogMessage) {
        this.predicate = predicate;
        this.notSatisfiedLogMessage = notSatisfiedLogMessage;
    }

    @Override
    public boolean test(final Number item) {
        final boolean isNotValid = predicate.negate().test(item);

        if (isNotValid) {
            log.warn("Invalid {}. Cause: {}", item, notSatisfiedLogMessage);
        }

        return predicate.test(item);
    }
}

并使用:

Predicate<Number> p = IS_NOT_NULL.and(IS_NOT_AN_INTEGER).and(IS_POSITIVE);

Another posibility:

public enum ConditionsToBeSatisfied implements Predicate<Number> {
    IS_NOT_NULL(Objects::nonNull, "Item is null"),
    IS_NOT_AN_INTEGER(item -> item instanceof Integer, "Item is not an integer"),
    IS_POSITIVE(item -> item instanceof Integer && (Integer) item > 0, "Item is negative");

    private final Predicate<Number> predicate;
    private final String notSatisfiedLogMessage;

    ConditionsToBeSatisfied(final Predicate<Number> predicate, final String notSatisfiedLogMessage) {
        this.predicate = predicate;
        this.notSatisfiedLogMessage = notSatisfiedLogMessage;
    }

    @Override
    public boolean test(final Number item) {
        final boolean isNotValid = predicate.negate().test(item);

        if (isNotValid) {
            log.warn("Invalid {}. Cause: {}", item, notSatisfiedLogMessage);
        }

        return predicate.test(item);
    }
}

and using:

Predicate<Number> p = IS_NOT_NULL.and(IS_NOT_AN_INTEGER).and(IS_POSITIVE);
永言不败 2024-09-06 01:43:52

枚举就像 Java 类,它们可以有构造函数、方法等。唯一不能用它们做的是 new EnumName()。这些实例是在您的枚举声明中预定义的。

Enums are like Java Classes, they can have Constructors, Methods, etc. The only thing that you can't do with them is new EnumName(). The instances are predefined in your enum declaration.

记忆里有你的影子 2024-09-06 01:43:52

这就是我的原因......

我用枚举的值填充了 JavaFX ComboBox。我有一个接口,可识别(指定一种方法:识别),它允许我指定任何对象如何向我的应用程序标识自身以用于搜索目的。该接口使我能够扫描任何类型对象的列表(无论对象可用于身份的字段)以进行身份​​匹配。

我想在我的组合框列表中找到与标识值匹配的内容。为了在包含 Enum 值的 ComboBox 上使用此功能,我必须能够在 Enum 中实现可识别接口(碰巧,在 Enum 的情况下实现起来很简单)。

Here's my reason why ...

I have populated a JavaFX ComboBox with the values of an Enum. I have an interface, Identifiable (specifying one method: identify), that allows me to specify how any object identifies itself to my application for searching purposes. This interface enables me to scan lists of any type of objects (whichever field the object may use for identity) for an identity match.

I'd like to find a match for an identity value in my ComboBox list. In order to use this capability on my ComboBox containing the Enum values, I must be able to implement the Identifiable interface in my Enum (which, as it happens, is trivial to implement in the case of an Enum).

夜未央樱花落 2024-09-06 01:43:52

我在接口中使用了内部枚举来描述策略以保持实例控制(每个策略都是单例)。

public interface VectorizeStrategy {

    /**
     * Keep instance control from here.
     * 
     * Concrete classes constructors should be package private.
     */
    enum ConcreteStrategy implements VectorizeStrategy {
        DEFAULT (new VectorizeImpl());

        private final VectorizeStrategy INSTANCE;

        ConcreteStrategy(VectorizeStrategy concreteStrategy) {
            INSTANCE = concreteStrategy;
        }

        @Override
        public VectorImageGridIntersections processImage(MarvinImage img) {
            return INSTANCE.processImage(img);
        }
    }

    /**
     * Should perform edge Detection in order to have lines, that can be vectorized.
     * 
     * @param img An Image suitable for edge detection.
     * 
     * @return the VectorImageGridIntersections representing img's vectors 
     * intersections with the grids.
     */
    VectorImageGridIntersections processImage(MarvinImage img);
}

枚举实现该策略的事实很方便,允许枚举类充当其封闭实例的代理。它还实现了该接口。

它是一种strategyEnumProxy:P客户端代码如下所示:

VectorizeStrategy.ConcreteStrategy.DEFAULT.processImage(img);

如果它没有实现接口,那么它就是:

VectorizeStrategy.ConcreteStrategy.DEFAULT.getInstance().processImage(img);

I used an inner enum in an interface describing a strategy to keep instance control (each strategy is a Singleton) from there.

public interface VectorizeStrategy {

    /**
     * Keep instance control from here.
     * 
     * Concrete classes constructors should be package private.
     */
    enum ConcreteStrategy implements VectorizeStrategy {
        DEFAULT (new VectorizeImpl());

        private final VectorizeStrategy INSTANCE;

        ConcreteStrategy(VectorizeStrategy concreteStrategy) {
            INSTANCE = concreteStrategy;
        }

        @Override
        public VectorImageGridIntersections processImage(MarvinImage img) {
            return INSTANCE.processImage(img);
        }
    }

    /**
     * Should perform edge Detection in order to have lines, that can be vectorized.
     * 
     * @param img An Image suitable for edge detection.
     * 
     * @return the VectorImageGridIntersections representing img's vectors 
     * intersections with the grids.
     */
    VectorImageGridIntersections processImage(MarvinImage img);
}

The fact that the enum implements the strategy is convenient to allow the enum class to act as proxy for its enclosed Instance. which also implements the interface.

it's a sort of strategyEnumProxy :P the clent code looks like this:

VectorizeStrategy.ConcreteStrategy.DEFAULT.processImage(img);

If it didn't implement the interface it'd had been:

VectorizeStrategy.ConcreteStrategy.DEFAULT.getInstance().processImage(img);
风吹雨成花 2024-09-06 01:43:52

是的,Enum 在 Java 中实现了一个接口,当我们需要实现一些与给定对象或类的可区分属性紧密耦合的业务逻辑时,它会很有用。

看一下下面的示例,它很容易理解,并显示了仅使用枚举的某些特定属性进行的操作的特殊情况。

interface EnumInterface {
   int calculate(int first, int second);
}

enum EnumClassOperator implements EnumInterface {
   ADD {
      @Override
      public int calculate(int first, int second) {
         return first + second;
      }
   },
   SUBTRACT {
      @Override
      public int calculate(int first, int second) {
         return first - second;
      }
   };
}

class Operation {
   private int first, second;
   private EnumClassOperator operator;
   public Operation(int first, int second, EnumClassOperator operator) {
      this.first = first;
      this.second = second;
      this.operator = operator;
   }
   public int calculate() {
      return operator.calculate(first, second);
   }
}

// Main Class
public class EnumTest {
   public static void main (String [] args) {
      Operation add = new Operation(20, 10, EnumClassOperator.ADD);
      Operation subtract = new Operation(20, 10, EnumClassOperator.SUBTRACT);
      System.out.println("Addition: " + add.calculate());
      System.out.println("Subtraction: " + subtract.calculate());
   }
}

这是另一个基本示例:

// Java program to demonstrate
// how an enum implements an
// interface

// Defining an interface
interface week {

    // Defining an abstract method
    public int day();
}

// Initializing an enum which
// implements the above interface
enum Day implements week {

    // Initializing the possible
    // days
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday;

    public int day()
    {
        return ordinal() + 1;
    }
}

// Main Class
public class Daycount {
    public static void main(String args[])
    {
        System.out.println("It is day number "
                        + Day.Wednesday.day()
                        + " of a week.");
    }
}

Yes, Enum implements an interface in Java, it can be useful when we need to implement some business logic that is tightly coupled with a discriminatory property of a given object or class.

Take a look at the example below, it's simple to follow and shows special cases of operations that are conducted with some particular properties of the enums only.

interface EnumInterface {
   int calculate(int first, int second);
}

enum EnumClassOperator implements EnumInterface {
   ADD {
      @Override
      public int calculate(int first, int second) {
         return first + second;
      }
   },
   SUBTRACT {
      @Override
      public int calculate(int first, int second) {
         return first - second;
      }
   };
}

class Operation {
   private int first, second;
   private EnumClassOperator operator;
   public Operation(int first, int second, EnumClassOperator operator) {
      this.first = first;
      this.second = second;
      this.operator = operator;
   }
   public int calculate() {
      return operator.calculate(first, second);
   }
}

// Main Class
public class EnumTest {
   public static void main (String [] args) {
      Operation add = new Operation(20, 10, EnumClassOperator.ADD);
      Operation subtract = new Operation(20, 10, EnumClassOperator.SUBTRACT);
      System.out.println("Addition: " + add.calculate());
      System.out.println("Subtraction: " + subtract.calculate());
   }
}

Here is one more base example:

// Java program to demonstrate
// how an enum implements an
// interface

// Defining an interface
interface week {

    // Defining an abstract method
    public int day();
}

// Initializing an enum which
// implements the above interface
enum Day implements week {

    // Initializing the possible
    // days
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday;

    public int day()
    {
        return ordinal() + 1;
    }
}

// Main Class
public class Daycount {
    public static void main(String args[])
    {
        System.out.println("It is day number "
                        + Day.Wednesday.day()
                        + " of a week.");
    }
}
寄居人 2024-09-06 01:43:52
interface SupportedAction {}

enum UserAction implements SupportedAction { 
   CREATE, DELETE, EDIT
}

enum StaffAction implements SupportedAction {
   CREATE, RENAME
}

...

public Set<SupportedAction> getSupportedActions()
interface SupportedAction {}

enum UserAction implements SupportedAction { 
   CREATE, DELETE, EDIT
}

enum StaffAction implements SupportedAction {
   CREATE, RENAME
}

...

public Set<SupportedAction> getSupportedActions()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文