假设我有一个具有一些属性的类:
public class MyClass {
public var fooProp:*;
public var barProp:Object;
}
实际上,这些之间有什么区别?是否有我以后可以分配给 fooProp 而不能分配给 barProp 的变量类型?
最佳答案
只有无类型变量才能保存值 undefined
.无类型变量是缺少任何类型注释或使用星号 *
的变量。类型注释的符号。
From ActionScript data type descriptors :
In previous versions of ActionScript, a variable with no type annotation was automatically assigned the Object data type. This is no longer true in ActionScript 3.0, which now includes the idea of a truly untyped variable. Variables with no type annotation are now considered untyped. If you prefer to make it clear to readers of your code that your intention is to leave a variable untyped, you can use the new asterisk (*) symbol for the type annotation, which is equivalent to omitting a type annotation. The following example shows two equivalent statements, both of which declare an untyped variable:
var x var x:*
Only untyped variables can hold the value undefined. If you attempt to assign the value undefined to a variable that has a data type, Flash Player or Adobe AIR will convert the value undefined to the default value of that data type. For instances of the Object data type, the default value is null, which means that Flash Player or Adobe AIR will convert the value undefined to null if you attempt to assign undefined to an Object instance.
举个例子:
var t:* = undefined;
trace(t); // outputs: undefined
var t:Object = undefined;
trace(t); // outputs: null
关于actionscript-3 - * 和 Object 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16933565/