HasStatic是什么意思java_java – getstatic在字节码中真正意味着什么?

我有这个字节码:

new java.lang.Object

// stack is [newObjectRef]

dup

// Stack is [newObjectRef newObjectRef]

invokespecial void java.lang.Object.()

// Stack is [initializedAsTypeObjectObjectRef]

putstatic java.lang.Object class.a

// variable a has the reference of new object

getstatic java.io.PrintStream java.lang.System.out

// Take the static value of System.out

// Stack is [initializedAsTypeObjectObjectRef System.out]

更新这是继续:

> ldc "test" // Stack is

> [initializedAsTypeObjectObjectRef System.out "test"]

> jsr pos.0000026C // call a subrutine invokevirtual void

> java.io.PrintStream.println(java.lang.String) // actually print the

> result // stack is (I think) Empty at this time ?

翻译是:

Object a = new Object();

a = "test";

System.out.print(a);

我的筹码好吗?

我不太清楚().

可能我将不得不使用out()setter和print()之后?

我总是习惯用out()打印..

解决方法:

如果我编译代码

public static void main(String[] args) {

Object a;

a = "test";

System.out.println(a);

}

并运行

javap -c Main

我知道了

public static void main(java.lang.String[]);

Code:

0: ldc #2 // String test

2: astore_1

3: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream;

6: aload_1

7: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V

10: return

您可以看到getstatic加载字段System.out

对象没有一个名为out()的方法,所以我不相信你在看你认为的代码.

getstatic获取静态字段,例如System.out是System的静态字段,所以如果你写的话

System.out.println();

这将导致使用getstatic

标签:java,bytecode

来源: https://codeday.me/bug/20190630/1335942.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值