package enumeration;
public class TestEnum {
public enum Jobs { ENGINEER,PROGRAMMER,SALES};
public enum NewDepartment {ENGINEER, MARKETING, SALES, HR};
public static void main(String[] args)
{
//compareTo
int i = NewDepartment.MARKETING.compareTo(NewDepartment.SALES);
int i2 = NewDepartment.MARKETING.compareTo(NewDepartment.ENGINEER);
int i3 = NewDepartment.MARKETING.compareTo(NewDepartment.MARKETING);
System.out.printf("NewDepartment.MARKETING compare to NewDepartment.SALES is %d\n", i);
System.out.printf("NewDepartment.MARKETING compare to NewDepartment.ENGINEER is %d\n", i2);
System.out.printf("NewDepartment.MARKETING compare to NewDepartment.MARKETING is %d\n", i3);
//equals
boolean b = NewDepartment.HR.equals(NewDepartment.SALES);
boolean b2 = NewDepartment.HR.equals(NewDepartment.HR);
System.out.printf("HR and NewDepartment.SALES are equal? %b\n", b);
System.out.printf("HR and HR are equal? %b\n", b2);
//getDeclaringClass
Class c = NewDepartment.ENGINEER.getDeclaringClass();
Class c2 = Jobs.ENGINEER.getDeclaringClass();
System.out.printf("NewDepartment.ENGINEER\'s declaring class is %s\n", c.getName());
System.out.printf("ENGINEER\'s declaring is %s\n", c2.getName());
//name
String s = NewDepartment.ENGINEER.name();
String s2 = NewDepartment.ENGINEER.toString();
System.out.printf("s and s2 are equals? %b\n", s.equals(s2));
//ordinal
int j = NewDepartment.ENGINEER.ordinal();
int j2 = NewDepartment.HR.ordinal();
System.out.printf("NewDepartment.ENGINEER\'s ordinal is %d\n", j);
System.out.printf("NewDepartment.HR\'s ordinal is %d\n", j2);
//valueOf
NewDepartment dept = NewDepartment.valueOf("HR");
boolean b3 = dept.equals(NewDepartment.HR);
System.out.printf("dept(%s) is HR? %b\n", dept.name(), b3);
//values
NewDepartment[] depts = NewDepartment.values();
System.out.printf("NewDepartment type has %d values, there are %s, %s, %s and %s.\n",
depts.length, depts[0].name(), depts[1].name(), depts[2].name(), depts[3].name());
}
}
相关推荐
java.lang.NoSuchFieldError: Companion 问题的解决方案
java.lang.NumberFormatException For inputstring 4294967295处理方法
报错 java.lang.OutOfMemoryError: PermGen space 报错 java.lang.OutOfMemoryError: Java heap 启动报错java.lang.ClassNotFoundException: 1catalina.org.apache.juli.FileHandler JAVA_OPTS="-server -Xms800m ...
java解决nested exception is java.lang.OutOfMemoryError Java heap space 解决OOM
idea启动项目报错 java.lang.NegativeArraySizeException解决方法
解决java.lang.StackOverflowError
java.lang.OutOfMemoryError: Java heap space 解决方法
java.lang.runtimeexception unexpected subelement
搜集整理关于java错误处理:java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space 资料整理
解决 java.lang.NoSuchFieldError: STRING at org.jbpm.identity.hibernate.PermissionUserType. 不用jbpm的jbpm-identity.jar 用这个就好
scrcpy投屏 AssertionError: java.lang.reflect.InvocationTargetException 安装这个版本的scrcpy即可。
java.lang.UnsupportedOperationException异常(csdn)————程序
记录java.lang.OutOfMemoryError:Java heap space的情况 文章内容: 一.问题描述+原因分析+解决方案 二.JVM调优说明 三.Tomcat添加到jvisualvm监控
java.lang.OutOfMemoryError: PermGen space 解决方案
java.lang.NoClassDefFoundError: de/javakaffee/kryoserializers/CurrencySerializer
java解决Handler processing failed; nested exception is java.lang.NoClassDefFoundError
java 9 中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包 而在 java 6/7 / 8 时关于这个API 都是捆绑在
java.lang.OutOfMemoryError处理错误
jdk升级之后出现异常:java.lang.NoClassDefFoundError: javax/xml/ws/Service 1、解决方案jdk降级至1.8之前 2、由于JDK9以后,去除了javax.xml包需要引入对应的jar包 <groupId>javax.activation <artifactId>...