类 不从它们扩展的 类 继承静态变量吗?
Do classes not inherit static variables from the classes they extend?
我有一个名为 debug
的静态变量,我试图在我的 class 中访问它,但它生成了一个错误。
Access of possibly undefined property debug
属性 是在基数 class 上定义的。
public class Animal {
public static var debug:Boolean;
}
public class Meerkat extends Animal {
public function Meerkat() {
trace("debug:" + debug); // error here
}
}
class 不能访问其超级 class 上的静态变量吗?
更新。这很奇怪。错误似乎消失了,但现在有一个警告,其中包含与错误相同的消息。
没错。静态变量不被子类继承。这已记录在案 here,它还建议通过声明一个具有相同名称的实例变量来解决它。不确定这种解决方法有多大用处,因为您也可以 将 静态变量更改为一个实例,而不是同时拥有两个实例(除非您确实需要在其他地方调用 Animal.debug
), 但它是 AS3, 它就在那里。
我有一个名为 debug
的静态变量,我试图在我的 class 中访问它,但它生成了一个错误。
Access of possibly undefined property debug
属性 是在基数 class 上定义的。
public class Animal {
public static var debug:Boolean;
}
public class Meerkat extends Animal {
public function Meerkat() {
trace("debug:" + debug); // error here
}
}
class 不能访问其超级 class 上的静态变量吗?
更新。这很奇怪。错误似乎消失了,但现在有一个警告,其中包含与错误相同的消息。
没错。静态变量不被子类继承。这已记录在案 here,它还建议通过声明一个具有相同名称的实例变量来解决它。不确定这种解决方法有多大用处,因为您也可以 将 静态变量更改为一个实例,而不是同时拥有两个实例(除非您确实需要在其他地方调用 Animal.debug
), 但它是 AS3, 它就在那里。