1.enum构造方法
enum Structure{
One("testOne"),Two("testTwo"),Three("testThree");
private String value;
private structure(String value){
this.value = value;
}
public String getValue(){
return this.value;
}
}
public void print(Structure s){
String value = s.getValue();
Toast.makeText(getApplication(),value,Toast.LENGTH_SHORT).show();
}
//调用
print(Structure.One);
2.enum带抽象构造方法
enum Structure{
One("testOne"){
public String LocaleValue(){
return "abstractOne";
}
},
Two("testTwo"){
public String LocaleValue(){
return "abstractTwo";
}
},
Three("testThree"){
public String LocaleValue(){
return "abstractThree"
}
};
private String value;
private structure(String value){
this.value = value;
}
public String getValue(){
return this.value;
}
public abstract String LocaleValue()
}
public void print(Structure s){
String value = s.LocaleValue;
Toast.makeText(getApplication(),value,Toast.LENGTH_SHORT).show();
}
//调用
print(Structure.One);
3.enum单态方法
enum Structure{
One("testOne");
private String value;
private structure(String value){
this.value = value;
}
public String getValue(){
return this.value;
}
}
public void print(Structure s){
String value = s.getValue();
Toast.makeText(getApplication(),value,Toast.LENGTH_SHORT).show();
}
//调用
print(Structure.One);