Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: overwritten equal method does not work

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default overwritten equal method does not work

    Hello. I have a code:
    @Override 
    	public boolean equals(Object o){
    		Assessment a=(Assessment) o;
    		if(this.getCandidate().equals(a.getCandidate())){
    			if(this.getAnswers().equals(a.getAnswers())){
    				if(this.getDate().equals(a.getDate())){
    					System.out.println("I am here");
    					return true;
    				}
    			}
    		}
    		return false;
    	}
    but my class does not call it and i can't see why any help? thanks!


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: overwritten equal method does not work

    A couple of things. First, how do you know you are not calling this method? I ask because you have a System.out.println() buried deep inside 3 if statements. It could well be the case that equals() is being called, but one of those conditions is false. Try putting a System.out.println() at the top of the method to confirm that the method is not being called.

    Secondly, perhaps I'm missing something, but if you (who can see your code) can't see why the method isn't being called how can we (who can't see that code).

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: overwritten equal method does not work

    Also posted at Equals method is not being called - Dev Shed
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. URGENT! Why won't my addToInvoice method work?
    By EDale in forum What's Wrong With My Code?
    Replies: 18
    Last Post: March 28th, 2013, 09:17 PM
  2. Replies: 1
    Last Post: January 23rd, 2013, 06:29 AM
  3. Help! Variable potentially getting Overwritten!
    By Hagstrom505 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: January 22nd, 2013, 07:51 PM
  4. [SOLVED] cannot get this method to work properly
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 2nd, 2011, 12:00 PM
  5. Replies: 3
    Last Post: April 18th, 2010, 10:08 AM