Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8818913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:13:26+00:00 2026-06-14T05:13:26+00:00

This is an update of the same question, which is partly solved. Java –

  • 0

This is an update of the same question, which is partly solved.

Java – Object properties does not differ

int size = 0;
int new = 10;
int default = 100;

ClassList filterList = new ClassList();
filterList.setSize(size);
filterList.setNew(new);
filterList.setDefault(default);

// Now i am creating another instance of the ClassList.

ClassList newList = ClassList(); 

Its strange that my newList has values of size, new and default, but with values as 0, 0 and 0 I tried to check whether the instances are same or not.

if(filterList .equals(newList)){
    Log.d("Is it equal","True");
    } else {
    Log.d("Its Not equal","false");
}

I got it false.

My POJO class is plain simple with getters and setters.

public class ClassList{

    private int size;
    private int new;
    private int default;

    public int getPageSize() {
        return size;
    }
    public void setPageSize(int size) {
        this.size = size;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:13:27+00:00Added an answer on June 14, 2026 at 5:13 am

    Default value for int is 0 that is why size, new and default has values 0, 0 and 0 on newly created instance

    Default equals comparison happens on == that is reference equality.
    You will need to override equals and hashcode

    From Java doc of Object#equals

    The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

    Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

    Sample Implementaion :

    public static class ClassList {
    
        private int size;
        private int newValue;
        private int defaultValue;
    
        public int getPageSize() {
            return size;
        }
        public void setPageSize(int size) {
            this.size = size;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null)
                return false;
            if (!(obj instanceof ClassList))
                return false;
            ClassList c = (ClassList) obj;
    
            return this.size == c.size && this.newValue == c.newValue
                    && this.defaultValue == c.defaultValue;
        }
    
        @Override
        public int hashCode() {
            return Integer.valueOf(size).hashCode()
                    + Integer.valueOf(newValue).hashCode()
                    + Integer.valueOf(defaultValue).hashCode();
        }
    }
    

    Note: new and default are reserved keywords in java. You can not define variable names for reserve keywords.


    References:

    • equals()
    • hashcode()
    • toString()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not the same old question about the validators and update panel compatibility.
[Update:] This question is related to: what does jQuery's click() do? jQuery's click() is
I use this code to update data in database table. Can reuse same code
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I asked the almost the same question before also, but i have not yet
I found this question which gives me the ability to check if a string
Continuing from my previous question which was solved by @Oleg. The solution seems to
This is a 2 part question which is pretty related, hence why I combined
QUESTION: can YOU use multiple statements and recordset, which operate simultaneously, using the same
FINAL UPDATE This question is about how to write a setup.py that will compile

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.