Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass values by reference

Status
Not open for further replies.

outis

Programmer
Jun 20, 2001
21
MX
Is there any way to use parameters by reference in Java, like it is used in C.
I need to call a servlet with several parameters from an JSP, then modify the value of the parameters to return them to the JSP, and I must not use instance variables.
 
You cannot pass primitive data types by reference. But Objects are automatically passed by reference, so you could just use Integers instead of ints.

I don't know though if this works just as well over a network connection - you could just try it out...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
The only problem with haslo's suggestion is that Integers are immutable so you would not be able to change it via the reference.

Charles
 
Yes, meadandale, you're right - outis, you'll have to write your own wrapper class for the int. Sorry...

public class IntWrapper
{
private int value;

public IntWrapper(int value) { setValue(value); }
public void setValue(int value) { this.value = value; }
public int getValue() { return this.value; }
}
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top