记录,备忘……
1 采用接口类
package test.constant;
/**
* 常量类
* 子内部类
*/
public interface Constant {
/**
* 公共常量
*/
class Public{
/** 用户表 */
public static final String TABLE = "test_user";
}
/**
* 数字
*/
class Number{
/** 数字0 */
public static final Integer ZERO = 0;
/** 数字1 */
public static final Integer ONE = 1;
}
interface Name{
String TOM = "tom";
String JERRY = "jerry";
}
}
2 采用枚举类
package test.constant;
/**
* 枚举类
* 子枚举类
*/
public class Enums {
/**
* 性别
*/
public enum Sex{
MALE("男"),
FEMALE("女");
private Sex(String value){
this.value = value;
}
private final String value;
public String getValue() {
return value;
}
}
}
以上两种方式比较推荐。
使用实例:
public static void main(String[] args) throws Exception{
System.out.println(Enums.Sex.FEMALE.getValue());
System.out.println(Constant.Number.ONE);
System.out.println(Constant.Public.TABLE);
}
完.