1. 程式人生 > >Java筆記——switch語句中使用Enum注意點

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