Search code examples
javaeclipseguava

Ignore property when generating equals and hashcode


Let's say I have a class Customer:

public class Customer {

private String firstName;
private String lastName;
private String doNotAddMeToEquals;

//Getters and Setters below

}

I'm using the Guava Eclipse Plugin in Eclipse to generate my equals() and hashCode() methods; however, I could just as well use the eclipse -> Source -> Generate HashCode / Equals. Either way...doesn't matter.

Is there a way to Annotate property doNotAddMeToEquals such that when I generate the equals & hashcode methods with the guava plugin that property doesn't show in the list?

Without altering the plugin or creating a template.

Thanks in Advance!!


Solution

  • It sounds like what you want is something like this:

    http://projectlombok.org/features/EqualsAndHashCode.html

    It lets you use annotations to drive what properties are included in the equals and hashcode methods.