gpt4 book ai didi

java - 了解 javap 输出

转载 作者:行者123 更新时间:2023-12-01 18:02:46 25 4
gpt4 key购买 nike

我有一个非常简单的类(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时,这就是我得到的:

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构造函数的调用。对父类(super class)构造函数的调用始终是构造函数中发生的第一件事。

关于java - 了解 javap 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39410411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com