可以使用hashCode()Java中Clock类中的方法获取时钟对象的哈希码。此方法不需要任何参数,它返回时钟对象可接受的哈希码。
演示此的程序如下所示-
import java.time.*;
public class Demo {
public static void main(String[] args) {
Clock c = Clock.systemDefaultZone();
int hashCode = c.hashCode();
System.out.println("The clock is: " + c);
System.out.println("The hash code is: " + hashCode);
}
}输出结果
The clock is: SystemClock[Etc/UTC] The hash code is: 227139178
现在让我们了解上面的程序。
使用方法获得指定时钟对象的哈希码hashCode(),然后显示该值。演示这的代码片段如下-
Clock c = Clock.systemDefaultZone();
int hashCode = c.hashCode();
System.out.println("The clock is: " + c);
System.out.println("The hash code is: " + hashCode);