News for hackers. Stuff that matters.
Re:Java 18 / JDK 18: General Availability by junon on Tuesday March 22, 2022 @11:21AM (#30767159)
If you actually understand Java, you'll understand why this is wrong. Only newbies have confusion about this, most of which dissipates when you actually learn the language you're working with. Tired of this 20+ year old "flaw" being used as cannon fodder.
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.

Re:Java 18 / JDK 18: General Availability by Banana699 on Tuesday March 22, 2022 @04:06PM (#30770835)
This is like saying that null references are a non-issue because it have been there since the 1970s and that "true" $LANGUAGE developers never collide head-first into invalid dereferences. If something is ridiculous and un-ergonomic, it stays ridiculous and un-ergonomic no matter what. Reference comparison by default is ridiculous and un-ergonomic.
Re:Java 18 / JDK 18: General Availability by junon on Wednesday March 23, 2022 @07:14AM (#30777246)
Null references exist in every language with the concept of null. It has nothing to do with Java specifically, and Java gives you a lot of information to debug them.
Re:Java 18 / JDK 18: General Availability by jraph on Wednesday March 23, 2022 @01:43PM (#30781156)
That's right, but that also doesn't answer the parent's point to which I fully agree.