了解 javap 输出
Understanding javap output
我有一个很简单的class:
package MyDev;
public class Point3D {
public Point3D(){x = 0; y = 0;z = 0;}
public float x, y, z;
public Point3D( float X, float Y, float Z )
{
x = X; y = Y; z = Z;
}
}
当我 运行 javap -c
在这个 class 上时,这就是我得到的:
C:\Projects\Development\MyJava\bin\MyDev>"C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javap" -c Point3D.class
Compiled from "Point3D.java"
public class MyDev.Point3D {
public float x;
public float y;
public float z;
public MyDev.Point3D();
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fconst_0
6: putfield #14 // Field x:F
9: aload_0
10: fconst_0
11: putfield #16 // Field y:F
14: aload_0
15: fconst_0
16: putfield #18 // Field z:F
19: return
public MyDev.Point3D(float, float, float);
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fload_1
6: putfield #14 // Field x:F
9: aload_0
10: fload_2
11: putfield #16 // Field y:F
14: aload_0
15: fload_3
16: putfield #18 // Field z:F
19: return
}
为什么? 为什么第二个构造函数也有签名 ()V,而不是 (FFF)V?
对于我的生活,我无法理解!
也就是调用Object
的构造函数。对超类构造函数的调用始终是构造函数中发生的第一件事。
我有一个很简单的class:
package MyDev;
public class Point3D {
public Point3D(){x = 0; y = 0;z = 0;}
public float x, y, z;
public Point3D( float X, float Y, float Z )
{
x = X; y = Y; z = Z;
}
}
当我 运行 javap -c
在这个 class 上时,这就是我得到的:
C:\Projects\Development\MyJava\bin\MyDev>"C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javap" -c Point3D.class
Compiled from "Point3D.java"
public class MyDev.Point3D {
public float x;
public float y;
public float z;
public MyDev.Point3D();
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fconst_0
6: putfield #14 // Field x:F
9: aload_0
10: fconst_0
11: putfield #16 // Field y:F
14: aload_0
15: fconst_0
16: putfield #18 // Field z:F
19: return
public MyDev.Point3D(float, float, float);
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fload_1
6: putfield #14 // Field x:F
9: aload_0
10: fload_2
11: putfield #16 // Field y:F
14: aload_0
15: fload_3
16: putfield #18 // Field z:F
19: return
}
为什么? 为什么第二个构造函数也有签名 ()V,而不是 (FFF)V? 对于我的生活,我无法理解!
也就是调用Object
的构造函数。对超类构造函数的调用始终是构造函数中发生的第一件事。