获取Java枚举描述

祁辰阳
2023-12-01

枚举类

package EnumGetDescription;

public enum SpreadSheetType {
    JXL( "Excel 97-2003 XLS (JXL)" ), POI( "Excel 2007 XLSX (Apache POI)" ),
    SAX_POI( "Excel 2007 XLSX (Apache POI Streaming)" ),
    ODS( "Open Office ODS (ODFDOM)" );

    private String description;


    /**
     * @param description
     * 描述
     */
    private SpreadSheetType( String description ) {
        this.description = description;
    }
    
	// 获取枚举描述
    public String getDescription() {
        return description;
    }
}

main主类

package EnumGetDescription;
/**
 * 获取枚举描述
 */
public class test {
    public static void main(String[] args) {
        for (SpreadSheetType value : SpreadSheetType.values()) {
            System.out.println(value.getDescription());
        }
    }
}

运行结果:
Excel 97-2003 XLS (JXL)
Excel 2007 XLSX (Apache POI)
Excel 2007 XLSX (Apache POI Streaming)
Open Office ODS (ODFDOM)

Process finished with exit code 0

 类似资料: