简体   繁体   中英

How do I track a parameter inside a method?

basically i need to track what the method does with the parameter, i can't modify the function to be tracked.

Ultimately what I'm trying to do is visually represent what the method does with the parameter.

I know java passes by value, so I'm having a hard time finding a workaround without modifying the method itself.

For example:

public void foo(int x){
   x+=10;
}

If I call it like this:

foo(2);

I need to be able to draw 2 rectangles, one with 2 width and one with 12.

I'd really appreciate some help, thanks in advance!

Java passes parameters by value, so the instruction inside the method

x += 10;

has no effect whatsoever on what was passed in, ie

int i = 2;
foo(i);
System.out.println(i); // 2

You would have to perform static code analysis to show what happens inside the method, noting that nothing actually happens to a variable passed in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM