0

Rhombus java interface

I have two java rhombus classes that implement a Rhombus interface. Both have an empty constructor and Another constructor that recieves 3 parameters(lower rhombus angle , vertical diagonal , center Point) One class has two fields: bottom point and left point. The other has three fields that are exactly as the constructor. My issue is Everything works great . I just have one tester that tries both Equals methods "Rhombus1.equals(rhombus2) I tried making the equals method compare anything I could think of and it still failed. All other getter methods of both classes work. (Already searched google, youtube so please dont tell me to go to google) Question is: what do I need to compare in here? Why is the tester failing me Do I need to use hashcode ( havent really used it before)

24th Nov 2022, 2:23 PM
Aviv Ozeri
Aviv Ozeri - avatar
1 Réponse
+ 1
Yes, you must also implement the hashCode method. Some guidance: https://www.baeldung.com/java-equals-hashcode-contracts
24th Nov 2022, 6:46 PM
Tibor Santa
Tibor Santa - avatar