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

后端 未结 3 1704
梦毁少年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:54

    Just use == if you're comparing primitives.

    Also, try not to use getters when working into the class because you have already access to all the fields (private or not).

    public boolean equals(Person p1)
    {
        return this.maximumBooks == p1.getMaximumBooks();
    }
    

提交回复
热议问题