Why does this produce an error in Flash Builder?:
package {
public class Foo {
override public function toString():String {
return "Foo";
}
}
}
Tab completion suggests that this is available for override...
Error message:
Multiple markers at this line:
-public
-1020: Method marked override must override another method.
-overridesObject.toString
Remove override
on the toString()
method.
There is a popular misconception among about the toString()
method, namely: if one wants to provide a custom implementation of a super class method, the override
keyword is needed. But in case of Object
, toString()
is dynamic and is attached at runtime, negating the need for overriding. Instead, the implementation is to be provided by the developer so one is not created at runtime. One just needs to write their own toString():String
implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With