2

Is it possible to override the equals() operator (ie. for customer classes where equality may be determined by 2 or more fields matching).

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
nso1
  • 595
  • 9
  • 18

2 Answers2

9

if you mean overloading "==" as a synonym for equals() then you can't, as ActionScript doesn't offer operator overloading. Just write an equals() method for your class and use that...

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
  • okay, got it. To clarify (i am going to mark as accepted, but for others i will just expand) - action script doesn't have a concept like equals and hashcode by default. You can use your own equals, but it is then really up to you as the developer to be consistent with its use (ie. its a convention you will have to adopt if you want to use an equals method). – nso1 Mar 04 '11 at 08:19
1

Using your own equals() method for a class doesn't solve how to check if a collection contains the desired object. In flex I've always had to write a for each and iterate over each member object to check if 2 or more fields are matching. Java allows the programmer to override hashCode() and equals() that's used automatically by collection interfaces.

S Nichols
  • 11
  • 2