Is there a way to override action scripts operators, in particular I would like to override the equals operator

邮差的信 提交于 2019-12-10 23:36:09

问题


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


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/818750/is-there-a-way-to-override-action-scripts-operators-in-particular-i-would-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!