How to check for value equality?

前端 未结 2 1872
遥遥无期
遥遥无期 2020-12-11 10:03

I\'m a Java-beginner, so please bear with this one.

I have a class:

class Point {
  public int x;
  public int y;

  public Point (int x, int y) {
           


        
2条回答
  •  甜味超标
    2020-12-11 10:29

    You'll want to override the hashCode() and equals() method. If you're using Eclipse, you can have Eclipse do this for you by going to Source -> Generate hashCode() and equals()... After you override these methods, you can call:

    if(a.equals(b)) { ... }
    

提交回复
热议问题