Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Object.toString Error

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
like image 987
Mr. Polywhirl Avatar asked Aug 21 '13 00:08

Mr. Polywhirl


1 Answers

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.

like image 64
usha Avatar answered Oct 19 '22 15:10

usha