How can i fix this equals on primitive type(int)

后端 未结 3 1699
梦毁少年i
梦毁少年i 2020-12-11 12:25

heres my code for a library application

package com.accenture.totalbeginner;

public class Person {
  private String name;
  private int maximumbooks;

  pub         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 12:41

    getMaximumbooks() returns a primitive type int not an Object. You have to compare it with == or in you case != (not equals)

    if (this.getMaximumbooks() != p1.getMaximumbooks())
    {
        return false;
    }
    return true;
    

提交回复
热议问题