Nark wrote on Tue, 03 February 2004 20:03 |
29. Why do you Canvas ?
|
sounds a little bit japlish
on a different note...
has any one ever noticed that the String object in java is the only object in java that is passed by value? and i dont think this is documented (or i havent found where it is documented). a while ago i remember trying to use a recurisve method that was passed a String and altered that string, and after the recursive method finished, there was no change to the string. i had to create a wrapper class that had one string as a member and pass that to the method. i just think its is a litle strange they diddn't tell us about this.
eg....
public class StringByValue {
public static void main(String psAryArgs[]) {
String sText = "";
recursiveMethod(sText, 0);
System.out.println("sText ->" + sText + "<-");
StringWrapper oText = new StringWrapper("");
recursiveMethod(oText, 0);
System.out.println("oText ->" + oText + "<-");
}
public static void recursiveMethod(Object poObject, int piCount) {
if (piCount == 10) {
return;
}
if (poObject instanceof String) {
String sText = (String)poObject;
sText += String.valueOf(piCount);
} else {
StringWrapper oText = (StringWrapper)poObject;
oText.fsText += String.valueOf(piCount);
}
recursiveMethod(poObject, piCount + 1);
}
static class StringWrapper {
String fsText = "";
public StringWrapper(String psText) {
fsText = psText;
}
public String toString() {
return fsText;
}
}
}
can cause big problems if you assume a String is passed by reference