The Artima Developer Community
Sponsored Link

Java Answers Forum
equals doubt

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Paulo Rezende

Posts: 2
Nickname: rhiegen
Registered: Apr, 2002

equals doubt Posted: Apr 26, 2002 12:43 PM
Reply to this message Reply
Advertisement
// ex1 suppose I have

class Value {
int i;
}

public class EqualsMethod2{
public static void main( String[] args){
Value v1 = new Value();
Value v2 = new Value();
v1.i = v2.i = 100; // ***
System.out.println(v1.equals(v2));
}
}

The answer is false.
Why is it false? I didn?t understand it.
In my opinion, since equals tests the contents of the object datamember i, I understood that in line // ***
v2.i receives 100, v1.i receives the memory address of v1.i, and so it?s false. Is my conclusion correct?
My doubt is about the difference between == and equals. I'm reading Thinking in Java and as I got to this part this doubt appear to me. Any suggestions?

Thanks in advance,

Rhiegen

Topic: Swing Applets Previous Topic   Next Topic Topic: How to serach a text file and display the results

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use