2
根據我對方法1中的每個局部變量定義的理解,爲本地人指示符添加了局部變量。爲什麼非靜態方法有額外的本地?還有,這是什麼?
來源:
public class A {
public void a() {}
public static void b() {}
}
生成的字節碼:
Compiled from "A.java"
public class A extends java.lang.Object
SourceFile: "A.java"
minor version: 0
major version: 50
Constant pool:
const #1 = Method #3.#12; // java/lang/Object."<init>":()V
const #2 = class #13; // A
const #3 = class #14; // java/lang/Object
const #4 = Asciz <init>;
const #5 = Asciz ()V;
const #6 = Asciz Code;
const #7 = Asciz LineNumberTable;
const #8 = Asciz a;
const #9 = Asciz b;
const #10 = Asciz SourceFile;
const #11 = Asciz A.java;
const #12 = NameAndType #4:#5;// "<init>":()V
const #13 = Asciz A;
const #14 = Asciz java/lang/Object;
{
public A();
Code:
Stack=1, Locals=1, Args_size=1
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 1: 0
public void a();
Code:
Stack=0, Locals=1, Args_size=1
0: return
LineNumberTable:
line 6: 0
public static void b();
Code:
Stack=0, Locals=0, Args_size=0
0: return
LineNumberTable:
line 11: 0
}
我猜! :) +1 – 2011-05-02 09:27:46
但是,從規範直接引用比猜測更好:-) – 2011-05-02 09:31:55
不能爭論的:-) – 2011-05-02 10:34:00