我不確定如何在Java中使用枚舉。我在下面的例子中使用它嗎?如何使用枚舉?
enum Sex {M, F};
public class person{
private person mom;
private Sex sex;
public person(Sex sex){
this.sex = sex;
//is this how i'd set sex?
}
public void setMom(person mom){
if(mom.sex == 'M'){}
//is this how i would check to see if the sex of the passed person argument is male?
}
}
Stackoverflow是**不是**谷歌搜索「Java枚舉教程」的替代品... – 2011-02-09 14:26:14