Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to look how this is called:</p> <pre><code>someObject.equals(someOtherObj); </code></pre> <p>This invokes the <code>equals</code> method on the instance of <code>someObject</code>. Now, inside that method:</p> <pre><code>public boolean equals(Object obj) { if (obj == this) { //is someObject equal to obj, which in this case is someOtherObj? return true;//If so, these are the same objects, and return true } </code></pre> <p>You can see that <code>this</code> is referring to the instance of the object that equals is called on. Note that <code>equals()</code> is non-static, and so must be called only on objects that have been instantiated.</p> <p>Note that <code>==</code> is only checking to see if there is <strong>referential</strong> equality; that is, the reference of <code>this</code> and <code>obj</code> are pointing to the same place in memory. Such references are naturally equal:</p> <pre><code>Object a = new Object(); Object b = a; //sets the reference to b to point to the same place as a Object c = a; //same with c b.equals(c);//true, because everything is pointing to the same place </code></pre> <p>Further note that <code>equals()</code> is generally used to also determine <strong>value</strong> equality. Thus, even if the object references are pointing to different places, it will check the internals to determine if those objects are the same:</p> <pre><code>FancyNumber a = new FancyNumber(2);//Internally, I set a field to 2 FancyNumber b = new FancyNumber(2);//Internally, I set a field to 2 a.equals(b);//true, because we define two FancyNumber objects to be equal if their internal field is set to the same thing. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload