Override equals and hashCode methods (part 2)

Eclipse can generate equals and hashCode methods for any class that has state fields (see post). What if you are writing code outside Eclipse, e.g., using a plain text editor? I usually copy java.lang.String.equals(Object) and modify it:
C:\jdk5> jar xvf src.zip java/lang/String.java
inflated: java/lang/String.java

C:\jdk5> gvim java/lang/String.java
It basically looks like this:
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
xxx anotherString = (xxx)anObject;
//compare the states of two objects
}
return false;
}
I then save this template in C:\tmp\equals.txt. Next time I need it inside vim, I just read it into vim with :r /equals.txt.

Followers

Pageviews Last 7 Days