For the Love of God, Please Use Java Records!
dev.to·22h·
Discuss: DEV
Flag this post

Remember when creating a simple data class in Java felt like doing some sorts of heavy labor? A handful of fields, 100 lines of code (well, not 100 lines, but is pretty close), and the existential dread of knowing you’d have to do it all again, even with the help of IDE? Yeah, Java 16 finally said “our bad” and gave us Records.

If you’re still writing POJOs like it’s 2010, buddy, we are not the same.

Why Records Are Like Finding $20 in Your Old Jeans

A real life use case: You want to store a name, age, and email. In the old days, you’d write a class, add fields, generate getters, generate setters (even though you don’t want them), generate equals(), generate hashCode(), generate toString(), and then realize you forgot to update equals() after adding a new field. The r…

Similar Posts

Loading similar posts...