码迷,mamicode.com
首页 > 编程语言 > 详细

java枚举类型

时间:2017-01-24 07:45:10      阅读:195      评论:0      收藏:0      [点我收藏+]

标签: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;
	}
}

  

java枚举类型

标签:str   getname   stat   static   turn   test   pack   nbsp   .com   

原文地址:http://www.cnblogs.com/anpajin/p/6346309.html

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