Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 重写Object.toString错误_Apache Flex_Flex4_Flash Builder_Overriding_Tostring - Fatal编程技术网

Apache flex 重写Object.toString错误

Apache flex 重写Object.toString错误,apache-flex,flex4,flash-builder,overriding,tostring,Apache Flex,Flex4,Flash Builder,Overriding,Tostring,为什么这会在Flash Builder中产生错误 包{ 公开课Foo{ 重写公共函数toString():String{ 返回“Foo”; } } } “制表符完成”表明这可用于覆盖 错误消息: Multiple markers at this line: -public -1020: Method marked override must override another method. -overridesObject.toString Foo没有扩展一个类;因此,没有可以重写的方法。只

为什么这会在Flash Builder中产生错误

包{
公开课Foo{
重写公共函数toString():String{
返回“Foo”;
}
}
}
“制表符完成”表明这可用于覆盖

错误消息:

Multiple markers at this line:
-public
-1020: Method marked override must override another method.
-overridesObject.toString

Foo没有扩展一个类;因此,没有可以重写的方法。只需从函数定义中删除override关键字,它就会编译

package {
  public class Foo {
    public function toString():String {
      return "Foo";
    }
  }
}
我要补充的是,这是许多ActionScript类所扩展的类的一个方法。但是,即使扩展对象,也不需要重写toString()方法。从文档中:

若要在Object的子类中重新定义此方法,请不要使用 覆盖关键字

像这样:

package {
  public class Foo extends Object {
    public function toString():String {
      return "Foo";
    }
  }
}

删除
toString()
方法上的
override


关于
toString()
方法,有一个流行的误解,即:如果想要提供一个超类方法的自定义实现,就需要
override
关键字。但是在
对象
的情况下,
toString()
是动态的,并且在运行时附加,不需要重写。相反,实现将由开发人员提供,因此不会在运行时创建。只需编写自己的
toString():String
实现。

。。。我尝试显式扩展对象,但它仍然抱怨。@Mr.polywhill我对我的答案做了一些编辑。即使在扩展对象时;您不需要使用覆盖。这是我的错。你是对的,动态属性是后期绑定的<代码>添加到动态类实例的属性是运行时实体…()