Click to See Complete Forum and Search --> : pass reference to method


zhcai
February 23rd, 2000, 06:30 PM
I'd like to initialize 2 parameter in a method, in C++, I can do like this:

void setParam(int* width, int* height)
{
*width = getWidth();
*height = getHeight();
}
int w, h;
setParam(&w, &h);




How Can I do this in Java?

mbutu
February 24th, 2000, 02:34 AM
All objects in Java are passed by reference, but not primitives.
If you wan't to pass an integer by reference put the int in a class like java.lang.Integer

example:
Integer i = new Integer(1);
method(i);

public void method(Integer integer)