java.lang.Enum.equals()%uA0如果指定的对象等于此枚举常量方法返回true。
声明
以下是java.lang.Enum.equals()方法的声明
public final boolean equals(Object other)
参数
-
other%uA0-- 这是与此对象进行相等比较的对象。
返回值
如果指定的对象等于此枚举常量此方法返回true。
异常
-
NA
例子
下面的例子显示java.lang.Enum.equals()方法的使用。
package com.yiibai import java.lang.* // enum showing topics covered under Tutorials enum Tutorials { topic1, topic2, topic3 } public class EnumDemo { public static void main(String args[]) { Tutorials t1, t2, t3 t1 = Tutorials.topic1 t2 = Tutorials.topic2 t3 = Tutorials.topic3 if(t1.equals(t2)) { System.out.println(t1 + " is equal to " + t2) } else if(t2.equals(t3)) { System.out.println(t2 + " is equal to " + t3) } else if(t1.equals(t3)) { System.out.println(t1 + " is equal to " + t3) } else { System.out.println("all 3 topics are different") } } }
让我们来编译和运行上面的程序,这将产生以下结果:
all 3 topics are different