枚举类型 java问题_JAVA 枚举类型的问题。

Input 的定义:

//: enumerated/Input.java

package enumerated;

import java.util.*;

public enum Input {

NICKEL(5), DIME(10), QUARTER(25), DOLLAR(100),

TOOTHPASTE(200), CHIPS(75), SODA(100), SOAP(50),

ABORT_TRANSACTION {

public int amount() { // Disallow

throw new RuntimeException("ABORT.amount()");

}

},

STOP { // This must be the last instance.

public int amount() { // Disallow

throw new RuntimeException("SHUT_DOWN.amount()");

}

};

int value; // In cents

Input(int value) { this.value = value; }

Input() {}

int amount() { return value; }; // In cents

static Random rand = new Random(47);

public static Input randomSelection() {

// Don't include STOP:

return values()[rand.nextInt(values().length - 1)];

}

} ///:~

Category 的定义:

package chapter19;

import java.util.EnumMap;

//import net.mindview.util.*;

import static enumerated.Input.*;

//import static net.mindview.util.Print.*;

enum Category {

MONEY(NICKEL, DIME, QUARTER, DOLLAR),

ITEM_SELECTION(TOOTHPASTE, CHIPS, SODA, SOAP),

QUIT_TRANSACTION(ABORT_TRANSACTION),

SHUT_DOWN(STOP);

private Input[] values;

Category(Input...types) { values = types; }

private static EnumMap categories =

new EnumMap(Input.class);

static {

for(Category c : Category.class.getEnumConstants())

for(Input type : c.values)

categories.put(type, c);

}

public static Category categorize(Input input) {

return categories.get(input);

}

}

在 Category 中声明实例时有错误,每个实例名下面都带下划线,错误是: The constructor Category(Input, Input, Input, Input) is undefined

但是我明明定义了啊,请问是什么问题

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值