深入了解Java核心类库??Objects类( 三 )
public static void main(String[] args) {Person p = new Person(1234,"张三");Person e = new Person(2345,"李四");System.out.println("e.getClass():"+e.getClass());System.out.println("e.hashCode():"+e.hashCode());System.out.println("e.toString():"+e.toString());}
输出结果:
e.getClass():class com.company.demo.Person
e.hashCode():114132791
e.toString():com.company.demo.Person@6cd8737
- 建议重写Object中的toString方法
2.3 Object源码package java.lang;import jdk.internal.HotSpotIntrinsicCandidate;public class Object {private static native void registerNatives();static {registerNatives();}@HotSpotIntrinsicCandidatepublic Object() {}@HotSpotIntrinsicCandidatepublic final native Class<?> getClass();@HotSpotIntrinsicCandidatepublic native int hashCode();public boolean equals(Object obj) {return (this == obj);}@HotSpotIntrinsicCandidateprotected native Object clone() throws CloneNotSupportedException;public String toString() {return getClass().getName() + "@" + Integer.toHexString(hashCode());}@HotSpotIntrinsicCandidatepublic final native void notify();@HotSpotIntrinsicCandidatepublic final native void notifyAll();public final void wait() throws InterruptedException {wait(0L);}public final native void wait(long timeoutMillis) throws InterruptedException;public final void wait(long timeoutMillis, int nanos) throws InterruptedException {if (timeoutMillis < 0) {throw new IllegalArgumentException("timeoutMillis value is negative");}if (nanos < 0 || nanos > 999999) {throw new IllegalArgumentException("nanosecond timeout value out of range");}if (nanos > 0) {timeoutMillis++;}wait(timeoutMillis);}protected void finalize() throws Throwable { }}
总结【深入了解Java核心类库??Objects类】本篇文章就到这里了,希望能给你带来帮助,也希望您能够多多关注趣讯吧的更多内容!
- 头腔共鸣简单方法
- 知己是一种什么感情
- 快手直播说话技巧
- 3699起 一图了解AGM G1:零下40度还能跑分 同环境下iPhone索尼全挂
- 央行降息与降准有什么区别 带你了解清楚!
- 想了解空调扇湿帘如何清洗 空调扇湿帘怎样清洗
- 红茶的作用
- 群众路线如何走
- 毛线帽子大了解决方法
- 最不了解自己的人的成语
