First Thoughts

When I first learned that I had to override equals I was confused on how I was supposed to do it. I thought I would have to do something deep like go into how java does it and change the code there. I could never have been more wrong. I just had to make a method called .equals() with the parameter of an object.

The Code

When I was coding I knew that I would have to individually go through each attribute of each object and compare them to see if they were equal. Using an article from Bael Dung (which has been a great resource during this project) I was able to split both of the objects attributes into String[] and use a for loop to iterate through the lists and compare each attribute. As soon as the loop detects attributes that are not equal it returns false. If the loop doesn’t detect anything it returns true. I tested it by changing the code a little and running it and it seemed to work as intended.

What Could I Have Done Better?

I wished I knew more about the debugging tool because I feel that it would be a lot more affective in testing. I also wish that I was able to come up with better variable names as I felt that some of them were stale.

What’s Next?

Now I need to work on JUnit tests for my project and learn more about how those work.


Java equals() and haschCode() Contracts