Java: enums and type safety
geniot
Posted on May 28, 2024
Using an enum is much better than using a bunch of constants because it provides type-safe checking. With numeric or String constants, you can pass an invalid value and not find out until runtime. With enums, it is impossible to create an invalid enum value without introducing a compiler error.
This is only true if it's Java talking to Java. But in modern ecosystems most likely it's a Java microservice that parses incoming JSON with some Jackson library. And then when it comes to persistence you are back to fighting enums again that cannot easily get mapped to PostgreSQL fields.
💖 💪 🙅 🚩
geniot
Posted on May 28, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024