Java 定义常量的几种方式

1. 类常量

/**
 * 类常量
 */
public class ConstParam {
	public static final String STATUS_1 = "1";// 状态
	public static final String STATUS_0 = "0";// 状态
}

 

2. 接口常量

/**
 * 接口常量
 */
public interface ScheduleType { 
	static final Integer NORMAL = 0; 
	static final Integer UPLOAD_FILE = 1; 
	static final Integer SCHEDULE_STATUS = 2; 
	static final Integer SCHEDULE_ASK = 3;
}

 

3.枚举常量

/**
 * 枚举常量
 */
public enum Test {
	ONE(1),TWO(2),THREE(3);
	
	private Integer code;
	
	private Test(Integer code){
		this.code = code;
	}
	
	public Integer getCode(){
		return this.code;
	}
}

 

4. 各常量的特性以及优缺点

待续......java

相关文章
相关标签/搜索