2012-09-24 27 views
4

我已經BCEL通 「這個」 參數

public class SecondClass{ 
     MainClass main; 
     public SecondClass(MainClass main){ 
       this.main=main; 
     } 
     .... 
} 

而且在MainClass(.class文件)有aMethod

public class MainClass(){ 
     public void aMethod(){ 
       //I want to insert 
       //SecondClass sc = new SecondClass(this); 
     } 
} 

我怎樣才能做到這一點與Apache BCEL?非常感謝!

回答

0

'this'作爲堆棧中的第一項傳遞。所以你可以將它存儲到本地變量的方式是使用jvm指令ALOAD和ASTORE。

例如,下面的代碼會生成相應的jvm指令。

public void test() 
{ 
    Test var1 = this; 
    Test var2 = this; 
} 

    ALOAD 0  
    ASTORE 1  
    ALOAD 0 
    ASTORE 2   
    RETURN   
+0

目前我不能嘗試你的方式。但是謝謝你的回答! –