Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Why Java records do not support inheritance?

Today I hit a wall, when I was about to add new functionality to the app. I had a record with data, but I needed some extra values. Adding this to the record would not make sense, becouse for most cases they will not be used and would be nulls, so I thought inheritance, which made perfect sense in this situation. But there is a problem , becouse Java records do not support inheritance, so I ended up with rewriting record to ugly POJO class with final values and getters.

So my question is basictly - why no inheritance. I understand there is not multiple inheritance becouse it's messy and hard to control on some point, but we also have final classes that cannot be inherited, why couldn't w e have records and final records?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

See the corresponding JEP:

Records are implicitly final, and cannot be abstract. These restrictions emphasize that the API of a record is defined solely by its state description, and cannot be enhanced later by another class or record.

The components of a record are implicitly final. This restriction embodies an immutable by default policy that is widely applicable for data aggregates.

The point is that reducing the realm of usage patterns, the compiler/JVM can do the sort of optimisations that the record concept is about.

Meaning: if you allow for subclassing, the runtime will have to deal with polymorphism. Which is not the intention behind records.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!