r/learnjava • u/Aeonitis • 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! 🙂
11
u/JazzyandSaxy May 06 '21
The var keyword might not be "groundbreaking" but if you learn the nuances of it, it can really be convenient in some situations especially with super long classnames. Check it out, it's not too complicated to figure out.
0
u/Migeil May 06 '21
What do you mean by nuances?
8
4
u/JazzyandSaxy May 06 '21
Rules of when you can use them, how they work behind the scenes, etc. (Ex. They are assigned a type at compile-time and it cannot be changed, can only be used as a local variable, etc.)
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.
2
2
u/large_crimson_canine May 06 '21
I would guess modules in Java 9. Enables you to defend against reflection attacks. But I’m also a noob so a pro might be able to chime in with something much more significant.
8
1
24
u/nutrecht May 06 '21
Here you go: https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features#_java_features_8_16
For me the var keyword, collection creation functions, records and string blocks are my favorites.