Enum类型使用

Enum类型的例子

PersonType.java内容:

package com.em.example;

public enum PersonType {
	
	BLACK("黑色人种"),WHITE("白色人种"),YELLOW("黄色人种");
	
	private String description;
	
	private PersonType(String description){
		this.description = description;
	}
	
	public String getValue(){
		return this.description;
	}

}



Test.java 文件内容

package com.test;

import com.em.example.PersonType;

public class Test {
	
	public static void main(String[] args) {
		
		for(PersonType pt : PersonType.values()){
			System.out.println(" personType : "+pt.getValue());
		}
		
		System.out.println(PersonType.BLACK.toString().equalsIgnoreCase("BlACK"));
	}

}



运行结果:


 personType : 黑色人种
 personType : 白色人种
 personType : 黄色人种
 false

你可能感兴趣的:(enum)