Passing reference - any dedicated class?

Hi there,

I need to pass an Integer to a function, and I want it to be modified by that function. However, AFAIK, this can be done only by passing my Integer argument as a component of an other class, for example:

class IntegerBox {

public Integer integer;

}

void myFunction( IntegerBox box ) {

box.integer= box.integer * 2; //just an example

}

So, where's the problem? I suppose there is already a class in Java's library, and I don't want to create any classes duplicating those in JDK. I just need a class having Object getObject() and void setObject( Object obj ).

If there is such a class, please tell me, thanks.

[682 byte] By [Madrasa] at [2007-11-27 4:29:17]
# 1
> I need to pass an Integer to a function, and I want it to be modified by that function. Just return the modified value. ~
yawmarka at 2007-7-12 9:38:14 > top of Java-index,Java Essentials,New To Java...
# 2
I know that returning values is possible in Java, but that's not what I'm asking about.
Madrasa at 2007-7-12 9:38:14 > top of Java-index,Java Essentials,New To Java...
# 3
There is no such class, because:1) it's trivial to write2) it's a bad ideaIf this value you're changing is state, then it should only be modified in the class that encapsulates the state. If it's not, then it shouldn't be modified in a class like that.
paulcwa at 2007-7-12 9:38:14 > top of Java-index,Java Essentials,New To Java...
# 4
> There is no such classOk, thanks for clear answer.
Madrasa at 2007-7-12 9:38:14 > top of Java-index,Java Essentials,New To Java...
# 5
There are at least three options:1. roll your own2. use an array with length 13. use java.util.concurrent.atomic.AtomicInteger http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicInteger.html
jsalonena at 2007-7-12 9:38:14 > top of Java-index,Java Essentials,New To Java...