r/java • • Aug 03 '25

Teach Me the Craziest, Most Useful Java Features — NOT the Basic Stuff

I want to know the WILD, INSANELY PRACTICAL, "how the hell did I not know this earlier?" kind of Java stuff that only real devs who've been through production hell know.

Like I didn't know about modules recently

398 Upvotes

279 comments sorted by

View all comments

16

u/Scf37 Aug 03 '25

ADT and domain modelling.

Java now has all the components required - products (record classes), sums (sealed hierarchies) and pattern matching enforcing compile-time validation.

Together with proper domain modelling, this forms very powerful tooling to write extendable and reliable business logic

7

u/mands Aug 03 '25

+1 - i've come to Java recently from FP and writing modern Java now feels very much like writing OCaml or Haskell (98) - but with great performance, libraries, etc. Plus it usually works first time.

3

u/bodiam Aug 03 '25

Any example of this in practice? I'm curious to see a demo of this.

7

u/syjer Aug 03 '25

https://www.infoq.com/articles/data-oriented-programming-java/

and

https://inside.java/2024/05/23/dop-v1-1-introduction/

are a good overview for java. (note: data oriented programming is quite a overloaded term)

1

u/[deleted] Aug 17 '25

[removed] — view removed comment

1

u/Scf37 Aug 17 '25

Unapply is already there, for records only though.

Id' say it is complete, with Java kinks. There is exhaustiveness checking, unapply (records only), conditional cases (case ... when ...). There is no matching by collections or values like case Foo(42, x) but I think this is intentional.