equals method - how to override

后端 未结 3 614
别那么骄傲
别那么骄傲 2020-12-22 12:35

I need help on to override the equals method. I have everything working except for the equals method. The equals method that I current

3条回答
  •  佛祖请我去吃肉
    2020-12-22 13:19

    If you are overriding equals method, then your above code is not correctly overriding equals method.

    use below code instead for overriding equals--

    public boolean equals(Object currency) {
    
    Currency newref = null;
    
    if (currency instanceof Currency) {
      newref = (Currency)currency;
    }
    return (this.dollars == newref.dollars) && (this.cents == newref.cents);
    }
    

提交回复
热议问题