News for hackers. Stuff that matters.
Re:Java 21 makes me like Java again by kaashif on Saturday September 16, 2023 @05:34PM (#37538922)
Nice article as someone familiar with sum types but not sum types in Java.

I don't know if sum types alone are enough to get me to like Java, pervasive nullability is still around and even rears its head multiple times in this article.

Re:Java 21 makes me like Java again by pharmakom on Saturday September 16, 2023 @05:42PM (#37538996)
It's also not expression orientated yet.
Re:Java 21 makes me like Java again by kaba0 on Sunday September 17, 2023 @02:40AM (#37542163)
Fortunately switch has now an expression variant. But I would die for an if-else expression (very subjective, but I would prefer a more verbose if-else to ternaries), and especially a try-catch expression!
Re:Java 21 makes me like Java again by leapis on Saturday September 16, 2023 @06:03PM (#37539198)
Nullable is a huge issue in Java, but annotation-based nullability frameworks are both effective and pervasive in the ecosystem (and almost mandatory, IMO).

I'm really excited about https://jspecify.dev/, which is an effort by Google, Meta, Microsoft, etc to standardize annotations, starting with @Nullable.

Re:Java 21 makes me like Java again by kaashif on Saturday September 16, 2023 @06:32PM (#37539464)
This can never be as effective as changing the default reference type to be not nullable, which would break backwards compatibility, so you can never really relax.

I know Kotlin is basically supposed to be that, it has a lot of other stuff though, and I haven't used it much.

Re:Java 21 makes me like Java again by martindevans on Saturday September 16, 2023 @07:04PM (#37539699)
That's basically what c# has done. But it's implemented as a warning which can be upgraded to an error. I think it might even be an error by default in new projects now.
Re:Java 21 makes me like Java again by kaashif on Saturday September 16, 2023 @08:30PM (#37540286)
Holy shit, how didn't I know they'd taken it this far? This is great! https://learn.microsoft.com/en-us/dotnet/csharp/nullable-ref...

They actually fixed the billion dollar mistake...

Re:Java 21 makes me like Java again by 5e92cb50239222b on Sunday September 17, 2023 @01:52AM (#37541915)
They didn't. A proper fix would require getting rid of null altogether in favor of ADTs or something similar. I work with C# daily and nulls can still slip through the cracks, although it's definitely better than @NotNull and friends.

I haven't worked with Kotlin in a while, but IIRC their non-nullable references actually do include runtime checks, so you cannot simply assign null to a non-nullable and have it pass at runtime like you can (easily) do in C#.

Re:Java 21 makes me like Java again by foolfoolz on Saturday September 16, 2023 @11:22PM (#37541213)
they won’t change the default reference type to non null. might take a few years but you can see their planned syntax here: https://openjdk.org/jeps/401
Re:Java 21 makes me like Java again by wayfinder on Saturday September 16, 2023 @06:17PM (#37539339)
I hope they succeed. So many people have tried.
Re:Java 21 makes me like Java again by mrkeen on Sunday September 17, 2023 @01:33AM (#37541830)
Not having nulls is easy.

Persuading Java devs not to use nulls is hard.

Re:Java 21 makes me like Java again by mrkeen on Sunday September 17, 2023 @01:31AM (#37541822)
I was just writing about nullability annotations!

https://news.ycombinator.com/item?id=37534184

Re:Java 21 makes me like Java again by netheril96 on Sunday September 17, 2023 @08:39AM (#37544433)
Nullable annotations don’t work with well with generics, or at least those tools I use.
Re:Java 21 makes me like Java again by wscp-dev on Sunday September 17, 2023 @01:59AM (#37541962)
With valhalla, we will have explicit nullability as well, so that problem will also be handled.