Objects are passed by reference Objects are accessible by reference, but there is no way to create a link to a primitive value (bytes, short, long). You either need to create an object to wrap an integer, or use a single array of elements.
public void sum(int[] i){
i[0] = ...;
}
or
public void sum(MyInt i){
i.value = ...;
}
public class MyInt{
public int value;
}
for your example, something like the following might work:
public int sum(int v){
return ...;
}
or
public int sum(){
return ...;
}
Update:
Additional / better description of object references:
Java . (, ). , java, (, ), , (, ) .
, ( ) .
:
, i, .
void primitive(int i){
i = 0;
}
, ref, .
void reference(Object ref){
ref = new Object();
}
,
void object(List l){
l.add(new Object());
}
MyInt .