Android 怎么自定义枚举类型的值
在已知可能输入值情况下,我们常常会用到枚举类型。在java中,怎么自定义枚举类型的值呢?请参考如下代码:
[java] public enum Point {
Satisfaction(1), Dissatisfied(-1);
private final int val;
private Point(int value) {
val = value;
}
public int getValue() {
return this.val;
}
}
public enum Point {
Satisfaction(1), Dissatisfied(-1);
private final int val;
private Point(int value) {
val = value;
}
public int getValue() {
return this.val;
}
}
在调用的时候,可以用Point.Satisfaction 和Point.Dissatisfied,如下所示:
[java] Judge(mContenxt, mGuid, Point.Dissatisfied);
Judge(mContenxt, mGuid, Point.Dissatisfied);
在方法Judge中,可以用getValue获取枚举的值。如下所示:
[java] public void Judge(Context context,String logGuid, Point point){
int point = point.getValue();
}
public void Judge(Context context,String logGuid, Point point){
int point = point.getValue();
}
补充:移动开发 , Android ,