java.lang.Enum.hashCode() 方法返回列舉常數的雜湊碼。
以下是java.lang.Enum.hashCode()方法的宣告
public final int hashCode()
NA
此方法返回列舉常數的雜湊碼。
NA
下面的例子顯示java.lang.Enum.hashCode()方法的使用。
package com.yiibai; import java.lang.*; // enum showing programming languages enum Language { C, Java, PHP; } public class EnumDemo { public static void main(String args[]) { // returns the name and hashCode of this enum constant System.out.print("Programming in " + Language.C.toString()); System.out.println(", Hashcode = " + Language.C.hashCode()); System.out.print("Programming in " + Language.Java.toString()); System.out.println(", Hashcode = " + Language.Java.hashCode()); System.out.print("Programming in " + Language.PHP.toString()); System.out.println(", Hashcode = " + Language.PHP.hashCode()); } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
Programming in C, Hashcode = 1569228633 Programming in Java, Hashcode = 778966024 Programming in PHP, Hashcode = 1021653256