I have a record like:
record Data(int x, int y, int a) {}
It gets default equals
and hashCode
methods.
How could I adjust those methods to have custom behavior? Lets say, I want to ignore a
in the methods.
I have a record like:
record Data(int x, int y, int a) {}
It gets default equals
and hashCode
methods.
How could I adjust those methods to have custom behavior? Lets say, I want to ignore a
in the methods.
Unfortunately, there is only one way to do this: You have to implement the methods yourself. Just overwrite these methods like you would do it with all other classes, too. In your own implementation, only use the properties you want. Your IDE usually helps you implement standard code and asks for the properties which should be included.
Alternatively, you can use tools like Lombok with annotations instead of implementation:
@Data
public class Data{
private int x;
private int y;
@EqualsAndHashCode.Exclude private int a;
}