「Java」java.lang.Class.isEnum()で列挙かどうかを判断するサンプル

Javaコード

package com.arkgame.study;

enum Fruit {
	Banana, 
	Grape, 
	Apple,
	;
}

public class IsEnumDemo {

	public static void main(String[] args) {

		System.out.println("Fruit:" + Fruit.Banana.toString());
		System.out.println("HashCode:" + Fruit.Banana.hashCode());

		boolean flag = Fruit.class.isEnum();
		System.out.println("列挙:" + flag);

	}

}

実行結果
Fruit:Banana
HashCode:366712642
列挙:true

Java

Posted by arkgame