News for hackers. Stuff that matters.
Re:Java 18 / JDK 18: General Availability by dtech on Tuesday March 22, 2022 @11:53AM (#30767601)
Just because something is a well known-flaw doesn't make it a glaring flaw.

There's a reason newer JVM languages like Kotlin use == as an alias for equals instead of reference equality.

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:29PM (#30768147)
What if you are interested in reference equality?
Re:Java 18 / JDK 18: General Availability by __float on Tuesday March 22, 2022 @12:39PM (#30768292)
In practice, how often are you interested in it? C# has `Object.referenceEquals()` because you _may_ want this sometimes. But to have reference equality be the default for something like `==` is a design flaw. Not one that can be fixed now, of course, but it will continue to cause bugs for years to come.

Sometimes, it happens in core Java libraries themselves: https://bugs.openjdk.java.net/browse/JDK-8274779

https://github.com/openjdk/jdk/blob/722d639fad2e4fc6eb2aabd4...

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:53PM (#30768500)
Dunno, I do a fair bit of low level java work, happens every once in a while.

Curiously, I don't do a lot of value-comparisons. Based on grepping in the repo for my search engine, I appear to do one every 1000 lines of code. May just be how I write code though. Some people seem to do that a lot more.

Re:Java 18 / JDK 18: General Availability by LordDragonfang on Tuesday March 22, 2022 @12:50PM (#30768458)
Python uses the `is` operator, which is semantically much more explicit (and arguably correct, though C#'s use of the `is` operator is probably more correct).

edit:

Kotlin uses `===`, which is another good option.

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @01:01PM (#30768619)
=== seems almost more dangerous. It's a lot easier to tell == from Objects.equals(a,b) than == from ===.
Re:Java 18 / JDK 18: General Availability by wiseowise on Tuesday March 22, 2022 @03:37PM (#30770486)
Seriously?
Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @05:06PM (#30771553)
Yes.

Look, languages are moving away from permitting constructs like "if (x = 1)" because it's difficult to distinguish from "if (x == 1)". Adding "if (x === 1)" into the mix is arguably a step backwards in terms of clarity.