Long type object is immutable, you cannot change the value of Long, once it is constructed with some value..
Better you put Long in some other object and then pass that object to the method, and change the value..
For ex..
Class MyLong
{
long value;
MyLong(long y)
{
value = y;
}
}
MyLong myLongObject = new MyLong(12);
method(12, myLongObject);
myLongObject.value will give the new value...
public long methodA(long m, MyLong x) {
x.value = newValue;
}
Main Topics
Browse All Topics





by: skeid21Posted on 2008-03-11 at 20:07:17ID: 21102688
In java, you are correct all simple types are pass by value. So there is no way to change the value of the x when it is a long. If you are changing the value of x then it seems that x needs to be persistent so it would make sense to have x be a member of a class. This would be the prefered Object Oriented approach to this problem.
Select allOpen in new window