I was looking at some code written by a guy I know the other day and I noticed something that appeared to work wrongly. After a quick discussion we realised that I was thinking in terms of what things did in C++ whereas the code was in Java. It struck me that with languages that are so similar as to be able to compile a good portion of the same code (not neccessarily enough of one particular piece to be able to completely successfully compile of course) there are going to be some very subtle bugs introduced when someone switches over and slips for a moment.
For those interested, the code was akin to
If I am correct, under C++ that would invoke foo's copy constructor and give the resulting new object to bar [ie, would be equivalent to Class1 bar(foo)], whereas in Java it will simply set bar to point to the same object as foo.
Has anyone else encountered code like this that they'd like to share. I'm interested in this now, and I'm sure some people would find it useful to have a quick guide to what not to assume.