Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Java record with final keyword
Although record classes in Java are implicitly final, it's valid to add the final
modifier/keyword when declaring a record:
final public record Person(String name, String location) {}
Does final
carry any special meaning here? Does it change the behavior of this record?
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Matthias Braun | (no comment) | Apr 14, 2025 at 17:25 |
The Java Language Specification (citing the Java SE 24 edition, released on 2025-02-07) addresses this here:
A record declaration is implicitly final. It is permitted for the declaration of a record class to redundantly specify the final modifier.
This suggests that using final
doesn't change a record's behavior.
0 comment threads