Java笔记——switch语句中使用Enum注意点

当枚举类型用在switch语句中时,语法有一点点特别。看例子:

/*
 * Copyright 2011 UDMS Project Zhejiang University
 */  
package udms.core.utils;

import sun.net.www.content.text.plain;
import udms.core.model.api.CDS;
import udms.core.model.impl.PrimitiveValueTypeEnum;

public class UDMSReader {
	
	
	/**
	 * read the feature from cds according to the fature name and type
	 * @param cds
	 * @param featureName
	 * @param featureType feature type
	 * @return the feature
	 */
	public Object readFeature(CDS cds, String featureName, String featureType){
		PrimitiveValueTypeEnum primitiveValueTypeEnum = PrimitiveValueTypeEnum.valueOf(featureType);
		return readFeature(cds, featureName, primitiveValueTypeEnum);
	}
	/**
	 * read the feature from cds according to the feature name and type
	 * @param cds 
	 * @param featureName
	 * @param pvte feature type
	 * @return the feature
	 */
	public Object readFeature(CDS cds, String featureName, PrimitiveValueTypeEnum pvte){
		Object object = null;
		switch (pvte) {
		case BLOB:				
			break;
		case BOOLEAN:
			break;
		case DATE:
			break;
		case DATETIME:
			break;
		case DECIMAL:
			break;
		case DOUBLE:
			break;
		case INTEGER:
			break;
		case LINK:
			break;
		case STRING:
			break;
		case URI:
			break;
		case VECTOR:
			break;
		default:
			break;
		}

		return object;
	}
	
}


注意在case标签中,BLOB不出现,即case PrimitiveValueTypeEnum.BLOB是不合法的。而在其他地方出现时则必须用PrimitiveValueTypeEnum.BLOB

你可能感兴趣的:(java,Date,object,String,vector,Integer)