3 Replies - 825 Views - Last Post: 05 July 2018 - 12:11 PM

#1 tekblade   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 21-December 17

Do you Consider an error occurs in this source

Posted 05 July 2018 - 10:44 AM

The source:
https://examples.jav...rial-beginners/

in equals implemented method:
this.id.equals //id is just a pool of type Long...


there should be something like:
public boolean equals(Object obj) {
    if ((obj instanceof PurchaseOrderPK) &&
        (((PurchaseOrderPK)obj).orderid == this.orderid))
      return true;
    return false;
  }



Regards

Is This A Good Question/Topic? 0
  • +

Replies To: Do you Consider an error occurs in this source

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,796
  • Joined: 12-June 08

Re: Do you Consider an error occurs in this source

Posted 05 July 2018 - 11:22 AM

What happens when you use it? Does it operate as expected?
Was This Post Helpful? 0
  • +
  • -

#3 tekblade   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 21-December 17

Re: Do you Consider an error occurs in this source

Posted 05 July 2018 - 12:00 PM

EDIT:
Specified above conditional uses Long type equals method. Can be closed

This post has been edited by tekblade: 05 July 2018 - 12:09 PM

Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 984
  • View blog
  • Posts: 3,879
  • Joined: 13-June 14

Re: Do you Consider an error occurs in this source

Posted 05 July 2018 - 12:11 PM

You should probably get your IDE to generate equals correctly. Bloch in Effective Java gives the rules that make for a good equals implementation. Remember that you'll also need to implement hashCode

Thankfully in Scala and Kotlin you can get away from having to write this boilerplate, as both languages give you facilities to implement value objects that give you those methods (and others, like toString) for free.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1