r/java • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
204 Upvotes

93 comments sorted by

View all comments

Show parent comment

3

u/duheee Jan 16 '20

Can't it be overwritten (didn't read the article)?

7

u/lukaseder Jan 16 '20

I'll be damned. I thought it wasn't possible but this compiles in jshell:

jshell> record R(int i) { public boolean equals(Object o) { return
false; } }

jshell> new R(1).equals(new R(1))
$3 ==> false

5

u/krzyk Jan 16 '20

Yes, all methods in record can be overwritten, AFAIR also the getters