Implementing the equals method in java

前端 未结 7 929
醉酒成梦
醉酒成梦 2021-01-18 15:39

This is my implementation of the equals class for a Coor class which is just contains 2 ints x and y. would this be the proper way of implementing this method?



        
相关标签:
7条回答
  • 2021-01-18 16:12

    Here’s a more straightforward way:

    public boolean equals(Object other) {
        return other instanceof Coor
          && ((Coor) other).x == x
          && ((Coor) other).y == y
    }
    
    0 讨论(0)
提交回复
热议问题