r/programming • u/jonjonbee • Jun 05 '18
Code golfing challenge leads to discovery of string concatenation bug in JDK 9+ compiler
https://stackoverflow.com/questions/50683786/why-does-arrayin-i-give-different-results-in-java-8-and-java-10
2.2k
Upvotes
View all comments
Show parent comment
6
u/evaned Jun 05 '18
Ditto. I was actually initially surprised that people would even think it's evaluated more than once; I think this is probably an illustration of how what languages you know shapes your thinking. (I'm still surprised -- c++ is by no means unique here -- but less so.)
It's also important because
a += bcan in fairly realistic scenarios be asymptotically more efficient thana = a + bfor some calls. (And will almost always be slightly faster unless the optimizer is able to remove an extra copy that is made with+.)