3 ms·
It’s not clear that this is how records work though. I think only the top level fields are final - I don’t think there’s an expectation that the array contents
by doctor_eval 7y ago
It’s not clear that this is how records work though. I think only the top level fields are final - I don’t think there’s an expectation that the array contents would be immutable - and since you can’t redefine the methods, this would have to be done by the compiler and I don’t think that’s the case.
Also, same problem happens with fields which are instances of classes; although the record is mutable, the instances are not. So I don’t think that’s the answer.
I also don’t think records can implement interfaces.
- kasperni 7y agoYes, you can override accessors and mutability is the main reason. It has been discussed a number of times on the various amber mailing lists, here is one [1]. Yes, records can implement interfaces. The syntax is {ClassModifier} record TypeIdentifier [TypeParameters] RecordHeader [SuperInterfaces] RecordBody [1] https://mail.openjdk.java.net/pipermail/amber-spec-experts/2019-March/001046.html https://mail.openjdk.java.net/pipermail/amber-spec-experts/2...
- doctor_eval 7y agoOK thanks. I misread an article as saying that records couldn’t be extended, but on rereading, it actually said that java.lang.Record couldn’t be extended other than by declaring a record. That makes a lot more sense, and certainly explains the use of methods instead of fields. Thanks! (I continue to dislike the syntax, FWIW)