Thomas said:
Uzytkownik <
[email protected]> napisal w wiadomosci
Yes you can. You must use any referancable type such as
Integer, Character and so on. Then any method will be able to change such
variable if obtained. Read about refrences and java class types.
Integer a;
somwhere in class:
void test(Integer x){
x = 1;
}
This is equivalent to:
void test(Integer x){
x = new Integer(1);
}
It changes which Integer object is referenced by the formal parameter x.
It has no effect on which Integer is referenced by a, or on a.intValue().
Instead, a needs to reference something that offers value-changing
syntax or methods. For example, you can assign to a specified element of
any int[] array:
void setOne(int[] data, int index){
data[index] = 1;
}
Similarly, if a references an object that has value-changing methods,
such as a StringBuilder:
void setOne(StringBuilder sb){
sb.setLength(0);
sb.append("ONE");
}
You can, of course, create a class of your own that has exactly the
value-changing methods you want.
Patricia