D
Dobieslaw Wroblewski
Hi,
Yesterday I tried to write something like (it's not the exact code):
void Foo(Color cl, JButton bn) {
cl = new Color(200, 200, 200);
bn = new JButton("Button");
bn.setbackground(cl);
}
And to my amazement - it did not work as I expected. Then I read in the
tutorial that the references to classes are passed by value in Java...
because everything is passed by value in fact ;-).
I was previously programming mainly in C++ and used passing arguments by
reference or by pointer quite often. Are there any well established
strategies of how to change the way of thinking (this is probably easier ;-)
and how to port the C++ code so that it uses passing by value only? I can
think of passing Object[] to functions like Foo, but this does not seem very
elegant...
DW.
Yesterday I tried to write something like (it's not the exact code):
void Foo(Color cl, JButton bn) {
cl = new Color(200, 200, 200);
bn = new JButton("Button");
bn.setbackground(cl);
}
And to my amazement - it did not work as I expected. Then I read in the
tutorial that the references to classes are passed by value in Java...
because everything is passed by value in fact ;-).
I was previously programming mainly in C++ and used passing arguments by
reference or by pointer quite often. Are there any well established
strategies of how to change the way of thinking (this is probably easier ;-)
and how to port the C++ code so that it uses passing by value only? I can
think of passing Object[] to functions like Foo, but this does not seem very
elegant...
DW.