0

所以我正在尝试使用 for 或 while 方法来打印主要方法中的所有对象。(安娜,考特尼,阿什利)

         public class JavaApplication56 {

        public enum details {

    Anna(" blue ", " blue"),
    Courtney(" red", " black"),
    Ashley(" yellow ", " green");

    String hairColor;
    String eyeColor;

    details(String hairColor, String eyeColor) {

        this.hairColor = hairColor;
        this.eyeColor = eyeColor;
    }

    public String getHair() {
        return hairColor;

    }

    public String getEye() {


        return eyeColor;
    }
}

我在我的主要方法下收到一个错误,指出二元运算符的操作数类型错误。第一种类型 int,第二种类型 details[]。

public static void main(String[] args) {

    JavaApplication56 ja = new JavaApplication56();

    for (int person = 0; person < details.values(); person++) {

        System.out.println(details.values()+details.);
    }

}
}
4

2 回答 2

1

或者更简单地说:

// details should be re-named Details
for (Details detail : Details.values()) {
  System.out.println(detail); // does it have a toString() override?
}
于 2013-07-22T00:03:01.570 回答
0

像这样:

public static void main(String[] args)
{

    JavaApplication56 ja = new JavaApplication56();

    for (int person = 0; person < details.values().length; person++)
    {
        System.out.println(details.values()[person].name());
    }

}
于 2013-07-22T00:00:18.653 回答