标签:str getname stat static turn test pack nbsp .com
java枚举类型
1。构造函数
2.ordinal 下标
3.对比
运行结果:
IPHONE5
Apple company IPHONE5
1
-3
================
IPHONE8
Apple company
4
package com.thinkgem.jeesite.test; public class Test { public static void main(String[] args) { Apple ap = Apple.IPHONE5; Apple ap1 = Apple.IPHONE8; System.out.println(ap); System.out.println(ap.getName()); System.out.println(ap.ordinal()); System.out.println(ap.compareTo(ap1)); System.out.println("================"); System.out.println(ap1); System.out.println(ap1.getName()); System.out.println(ap1.ordinal()); } } enum Apple { IPHONE4, IPHONE5("IPHONE5"), IPHONE6, IPHONE7, IPHONE8; private String name; Apple() { name = "Apple company "; } Apple(String name) { this.name = "Apple company " + name; } public String getName() { return name; } }
标签:str getname stat static turn test pack nbsp .com
原文地址:http://www.cnblogs.com/anpajin/p/6346309.html