Vincent Vauban’s Post

🧩☕ GUESS THE JAVA VERSION: SEALED + RECORDS 🔸 TRY THIS QUICK QUIZ What Java version do you need for this code? class Example { sealed interface Shape permits Circle, Square {} record Circle(double radius) implements Shape {} record Square(double side) implements Shape {} } Choose one: ▪️ Java 6 ▪️ Java 9 ▪️ Java 13 ▪️ Java 17 ▪️ Java 23 🔸 STOP HERE AND GUESS ✅ (Scroll only when you’re ready.) 🔸 TL;DR ▪️ If you see sealed ... permits ... → think Java 17. ▪️ If you see record → you’re at least on Java 16. 🔸 ANSWER ✅ Java 17 🔸 WHY IT’S JAVA 17 ▪️ sealed + permits = you control who can implement/extend a type (closed hierarchy). This became a standard feature in Java 17. ▪️ record = a compact way to write small immutable data classes (fields + constructor + getters + equals/hashCode/toString). Records exist since Java 16, so Java 17 supports them too. ▪️ Together, sealed + record is a clean way to model “only these shapes exist”. 🔸 TAKEAWAYS ▪️ Sealed types help you design safe, closed APIs (no surprise implementations). ▪️ Records remove boilerplate for data-only types. ▪️ This combo is perfect for domain models like Shape → Circle/Square and later works great with pattern matching (especially with switch). 🔸 YOUR TURN 💬 Would you use sealed hierarchies in your production code, or do you prefer “open” extension points? #Java #Java17 #SealedClasses #Records #CleanCode #SoftwareArchitecture #Programming #JVM #BackendDevelopment #LearningJava #JavaTips Go further with Java certification: Java👇 https://lnkd.in/eZKYX5hP Spring👇 https://lnkd.in/eADWYpfx SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap Src: https://lnkd.in/exEmMjwC

  • Guess Java Version

To view or add a comment, sign in

Explore content categories