反编译查看printf()的方法

源代码:

 1 package test2;
 2 
 3 public class ExplorationJDKSource {
 4 
 5     /**
 6      * @param args
 7      */
 8     public static void main(String[] args) {
 9         System.out.println(new A());
10     }
11 
12 }
13 
14 class A{}

输出结果:

test2.A@15db9742

反编译结果如下:

分析:(官话)

前面示例中,main方法实际上调用的是:

public void println(Object x),这一方法内部调用了String类的valueOf方法。

valueOf方法内部又调用Object.toString方法:

public String toString() {

return getClass().getName() +"@" +

Integer.toHexString(hashCode());

}

hashCode方法是本地方法,由JVM设计者实现:

public  native int hashCode();

调用了父类的方法。

猜你喜欢

转载自www.cnblogs.com/cxy0210/p/11728488.html