0

I wish to send an 'int' to a function that changes its value. I want to send it by reference so the new value of 'int' is kept after returning to the callee. What is the most effective way to do it?

I know that I can use a wrapper class Integer that sends an object of an 'int'. However, I can't figure out how to change the value of this class, so the change will prevail after returning to the callee.

Thanks for your help.

user3189985
  • 189
  • 5
  • 14

1 Answers1

3

Nothing can be passed by reference in java, you need a wrapper, a conventional bean would do:

public class MyWrapper {
int x;
public void setX(int x){
    this.x = x;
  }
}
Community
  • 1
  • 1
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311