Why Aren’t Record Classes Part of the Public API in JRE23?

0
2
Asked By CuriousCoder93 On

I've noticed that the public API of JRE23 doesn't include record classes, with all their usage being found in internal packages like `com.sun`. It seems like records might not be good for situations where maintaining backward compatibility is necessary. Can anyone explain why that is?

1 Answer

Answered By TechGuru88 On

Actually, there are records in the JRE23 API, like `UnixDomainPrincipal` and other classes. But your point stands about backward compatibility. Records are generally more rigid than traditional classes. Once you define a record, changing its fields can break existing code that depends on that structure. So, it’s wise to avoid using them in public APIs unless you’re sure your design will remain stable for the long haul.

InfoSeeker01 -

Right! Adding a new field to a record can easily break code that destructures it, which is a real concern for developers. Once we get more features, like deconstruction patterns, that could help with compatibility, but removing fields or changing types is still a big no-no.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.