News for hackers. Stuff that matters.
Re:Java 18 / JDK 18: General Availability by MBCook on Tuesday March 22, 2022 @12:14PM (#30767903)
For what it’s worth any decent IDE will warn you about that. But as a Java developer you know it’s wrong, Strings are objects and that’s not how you compare objects.

The tricky one is numbers.

Integer == int // fine

int == int // fine

numVarOne == numVarTwo // Uh-oh

In that third example you better make sure they aren’t both boxed objects or BigDecimals.

I’ve almost never seen the string one for some reason. It’s always boxed numbers.

Again, a good IDE is worth a ton.

Re:Java 18 / JDK 18: General Availability by vips7L on Tuesday March 22, 2022 @03:05PM (#30770107)
Integer == Integer actually works... sometimes, as long as you're within the Integer cache. It gets people all the time though.
Re:Java 18 / JDK 18: General Availability by MBCook on Tuesday March 22, 2022 @03:24PM (#30770329)
Yep. I’ve been bitten by that myself. It’s sneaky because it may pass all your unit tests because you’re using small numbers. Then it gets to prod with record number 2718 and kablooie.