java的枚举类的values_java – 使用泛型类Enum.values扩展枚举

我试图用一个枚举的所有可用值来初始化一个泛型类. HEre是我想要的工作方式:

public class MyClass> {

E[] choices;

public MyClass() {

choices = E.values();

}

但是,Eclipse中不接受对E.values的调用,表示该方法对于此E是未定义的.

使用这个构造函数是接受的,但是要求调用者提供这些值:

public MyClass(E[] e) {

choices = e;

}

在我发现的文档中:

Java programming language enum types are much more powerful than their

counterparts in other languages. The enum declaration defines a class

(called an enum type). The enum class body can include methods and

other fields. The compiler automatically adds some special methods

when it creates an enum. For example, they have a static values method

that returns an array containing all of the values of the enum in the

order they are declared.

有没有办法解决这个问题?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值