enum 使用
public class Demo {
public static int initValue = 0 ;
public enum Delta {
ONE ( 1 , " delta is one" ) {
@Override
public int add ( ) {
return initValue += getValue ( ) ;
}
} ,
TOW ( 2 , "delta is tow" ) {
@Override
public int add ( ) {
return initValue += getValue ( ) ;
}
} ,
THREE ( 3 , "delta is three" ) {
@Override
public int add ( ) {
return initValue += getValue ( ) ;
}
} ;
private int value;
private String description;
Delta ( int value, String description) {
this . value = value;
this . description = description;
}
public abstract int add ( ) ;
@Override
public String toString ( ) {
return description;
}
public int getValue ( ) {
return value;
}
public String getDescription ( ) {
return description;
}
}
@Test
public void test ( ) {
initValue = 10 ;
System. out. println ( Delta. ONE. add ( ) ) ;
System. out. println ( Delta. ONE. add ( ) ) ;
System. out. println ( Delta. TOW) ;
}
}