News for hackers. Stuff that matters.
Re:In Java 3 = 12 by brobdingnagians on Wednesday November 15, 2017 @03:16AM (#15702242)
This isn't at all surprising if you know how Java works; you could probably point out this kind of a strange feature case in nearly any language if you look hard enough.

It does left to right order of operands, so 1 + 2 happens as integer addition since both operands are integers, then + "=" does string concatenation since one of the operands is a String, then "3=" + 1 evaluates as a concatenation since one of the operands is a String, giving "3=1" + 2, which evaluates to "3=12" by the same logic. Parenthesis solves this by explicitly specifying order of operations.

And explicitly specifying order of operations is almost always a good idea for making sure it does what you want and maintenance purposes.

Re:In Java 3 = 12 by Peaker on Wednesday November 15, 2017 @03:30AM (#15702307)
> you could probably point out this kind of a strange feature case in nearly any language if you look hard enough

I disagree. I think it's a product of bad language design.

Re:In Java 3 = 12 by reacweb on Wednesday November 15, 2017 @04:30AM (#15702555)
I disagree. I am not an expert of java language subtleties, but I had no problem to predict and explain this output. I think it is a product of the language simplicity. I have a deeper knowledge of C and more experience, but I regularly fail to predict output in similar exercises.
Re:In Java 3 = 12 by guelo on Wednesday November 15, 2017 @04:11AM (#15702476)
The bad design here is having implicit type conversion at all. The few characters you save with this rarely used feature are not worth the potential confusion. But it is a trade-off, Java is normally criticized in the other direction, for forcing you to be overly explicit.