java 枚举类型的使用

来源:互联网 发布:淘宝屏蔽关键词 编辑:程序博客网 时间:2024/05/22 10:22

有的时候我们使用publit static final 来定义常量,这样的常量在jdk1.5以后可以使用枚举的方式来定义。

在这里我只列出 自定义函数的枚举类型

public enum AreaConstant {    /**     * 代码     */    private String code;    /**     * 代码所对应的值     */    private String value;    /**     * 构造函数     *      * @param code code     * @param value value     */    private AreaConstant(String code, String value) {        this.code = code;        this.value = value;    }    /**     * @return AreaConstant the code     */    public String getCode() {        return code;    }    /**     * @param AreaConstant code the code to set     */    public void setCode(String code) {        this.code = code;    }    /**     * @return AreaConstant the value     */    public String getValue() {        return value;    }    /**     * @param AreaConstant value the value to set     */    public void setValue(String value) {        this.value = value;    }}

自定义函数的枚举类型 构造方法为私有化。具有get和set属性的方法,然后列出需要枚举的类型。

原创粉丝点击