BCEL Pass parameter "this"

I have

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

And in MainClass (.class file) there is aMethod

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

How to do this with Apache BCEL? Thank you very much!

+4
source share
1 answer

'this' is passed as the first item on the stack. so that you can save it in a local variable with jvm ALOAD and ASTORE instructions.

For example, the following code generates the corresponding jvm instructions.

 public void test() { Test var1 = this; Test var2 = this; } ALOAD 0 ASTORE 1 ALOAD 0 ASTORE 2 RETURN 
0
source

Source: https://habr.com/ru/post/1435828/


All Articles