r/learnjava • • May 06 '21

What are the most groundbreaking Java features since Java 8, and why?

All the features from Java 9-16 will all fit a use case, but I'd love to make time to go through every one of them, but I need to prioritize, or maybe I underestimated one of them.

If you've had a work scenario where they helped, that'd be great too.

You tell me! 🙂

52 Upvotes

11 comments sorted by

View all comments

9

u/xToniGrssx May 06 '21

I think I would start with some of the more recent ones like records, sealed classes, maybe the var keyword as others mentioned it before.

Records are incredibly useful for omitting lots of boilerplate code, sealed classes offer a stricter hierarchy constraint, the var keyword in itself might not be that fascinating, but when you were to replace HashMap<String,Set<Integer>> with only three characters, I often find myself using them. I also use the switch expression, or enhanced switch case a lot, that’s definitely worth to check out!

But bear in mind, that most of these features have a long time before they’ll be used in 90% of today’s production code, from my experience at least in the banking sector they are struggling to move on to Java 11, hell,most of them only recently adopted Java 8, and that is the better scenario.