actionscript-3 - ActionScript 3 覆盖方法 + 提高可见性

标签 actionscript-3 flash methods overriding

当我扩展一个类时,我想覆盖方法并更改它们的可访问性,就像 protected 方法应该在某个类中公开一样。当我编译它时说:“不兼容的覆盖”。我无法降低也无法提高可见度。

减少没有意义,我不需要它,但我能够在 Java 中增加方法可见性。为什么不在 ActionScript 3 中?

public class OldClass
{
    protected function doStuff() : void
    {}
}
public class NewClass extends OldClass
{
    override public function doStuff() : void
    {}
}

我做错了什么吗?

最佳答案

不,你没有做错任何事。这就是语言的工作原理。来自documentation (强调):

Static methods are not inherited and cannot be overridden. Instance methods, however, are inherited by subclasses and can be overridden as long as the following two criteria are met:

  • ...

  • The override method must have the same level of access control as the base class method. Methods marked as internal have the same level of access control as methods that have no access control specifier.

  • The override method must have the same number of parameters as the base class method.

  • The override method parameters must have the same data type annotations as the parameters in the base class method.

  • The override method must have the same return type as the base class method.

关于actionscript-3 - ActionScript 3 覆盖方法 + 提高可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13986021/

相关文章:

php - 流交互 As3 -> PHP -> Mysql -> C++

performance - 将代码放在单独的函数中怎么可能提高性能?

flash - ( ActionScript 3)打开上下文菜单时获取点击位置

python:将两个字符串h&m转换成24小时时间格式

php - 将 PHP 爆炸字符串转换为 AS3

apache-flex - 在 Flex 的 HTTP Post 中上传任意数据

asp.net - 在 ASP.NET 网站中嵌入视频的有效选项是什么?

javascript - Flash 与 (Ex)Canvas 与 SVG/VML

objective-c - Objective C类之间的通信

java - 为什么我的代码在检查两个相等的字符串时返回 false?