码迷,mamicode.com
首页 > 其他好文 > 详细

枚举类型总结

时间:2017-11-02 20:07:08      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:string   ntc   this   enum   eof   总结   type   login   valueof   

1. 枚举类型总结

 

public enum OperationEnum {

        LOGIN;   // 登录
        
    }

 

     int ordinal = OperationEnum.valueOf("LOGIN").ordinal();
        String name = OperationEnum.valueOf("LOGIN").name();
        
        System.out.println(ordinal);   // 0
        System.out.println(name);      // LOGIN

2.  枚举类型举例2

int ordinal = ATTRIBUTE_TYPE.valueOf("AGREEMENT").ordinal();  // 1
int ordinal2 = ATTRIBUTE_TYPE.AGREEMENT.ordinal(); // 1
System.out.println(ordinal);   //  1
System.out.println(ordinal2); // 1

String name = ATTRIBUTE_TYPE.valueOf("AGREEMENT").name(); // AGREEMENT
String name2 = ATTRIBUTE_TYPE.AGREEMENT.name();       // AGREEMENT
System.out.println(name);      // AGREEMENT
System.out.println(name2); // AGREEMENT

String getValue = ATTRIBUTE_TYPE.AGREEMENT.getValue(); // readc
String value = ATTRIBUTE_TYPE.AGREEMENT.value;      // agreementc
System.out.println(getValue);  // readc
System.out.println(value); // agreementc

ATTRIBUTE_TYPE attribute_type = ATTRIBUTE_TYPE.AGREEMENT;  //AGREEMENT
System.out.println(attribute_type);   //  AGREEMENT


public enum ATTRIBUTE_TYPE { READ("readCount"), AGREEMENT("agreementCount");

    
private final String value; ATTRIBUTE_TYPE(String value) { this.value = value; } public String getValue() { return value; } }

 

枚举类型总结

标签:string   ntc   this   enum   eof   总结   type   login   valueof   

原文地址:http://www.cnblogs.com/an5211/p/7773764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!