【发布时间】:2020-06-30 10:09:02
【问题描述】:
我有一个问题,代码中的注释在哪里,如下:
我的代码试图从我的getFullCollection() 方法中提取 7 张随机卡片,
但是,它不允许 Me 返回任何值,因为它声明 void 方法不能返回值。代码:
public class Packs {
Deck classicSet = new Deck() {
public void getFullCollection() {
classicSet.getFullCollection();
Random PO = new Random();
int number;
for(int counter = 1; counter<=7; counter++) {
number = 1+PO.nextInt(10000000);
if(number < 41650) {
return packag.Cards.Rarity.Common; //the problem
}
上面写着:
void 方法不能返回值
public void getFullCollection() throws IOException{
Cards Shuriken = new Attacks(3, 2, packag.Cards.Effects.Return, packag.Cards.Class.Ninja, packag.Cards.Rarity.Common, ImageIO.read(new File("Shuriken.png")));
System.out.println(Shuriken.toString());
this.cards.add(Shuriken);
我尝试删除我的 getFullCollection() 类上的 void 返回类型并将其替换为 public int getFullCollection(),但它不起作用
class Attacks extends Cards {
private int damage;
private int Mana;
private final Effects effects;
private BufferedImage card;
private final Rarity rarity;
private final Class class1;
Attacks(int damage, int Mana, final Effects effects, final Class class1, final Rarity rarity, BufferedImage card) {
super(Mana, effects, rarity, class1, card);
this.damage = damage;
this.rarity = rarity;
this.class1 = class1;
this.effects = effects;
this.Mana = Mana;
this.card = card;
}
这种方法是我在getFullCollection方法中制作卡片的方法。
【问题讨论】: