ag******@yahoo.com wrote:
Also, a newbie observation, that Double (capital D) didn't get passed
as a reference. Why not? This seems dumb to me, as all other objects
seem to get passed by reference.
To be pedantic, a reference to the object instance is passed by value.
So that means you can invoke methods that change the object instance and
the object instance is changed for the caller as well.
But you cannot change the reference to point to a difference reference
and expect that to register with the caller.
For example (not compiled),
public class Example
{
public static final String NL =
System.getProperty("line.separator");
public static void example(StringBuffer buf, Double d)
{
buf.append("d = ").append(d).append(NL);
d = new Double(2.78);
buf.append("d = ").append(d).append(NL);
}
public static void main(String args[])
{
StringBuffer buf = new StringBuffer();
Double d = new Double(3.14);
example(buf, d);
buf.append("d = ").append(d).append(NL);
System.out.println(buf.toString());
}
}
The output should be:
d = 3.14
d = 2.78
d = 3.14
HTH,
Ray
--
XML is the programmer's duct tape.