ActionScript 中具有多个基本类型的强类型集合(Vector)?
ActionScript 是否有任何方法处理具有多个基本类型的强类型列表?
我实际上正在寻找诸如 Vector
之类的东西?
是否可以?
或者唯一的方法是创建我自己的类,该类在构造函数中接受 String
和 Number
并创建一个 Vector
代码> 那个类之外?
Does ActionScript have any way of handling a strongly typed list with multiple base types?
I am actually looking for something such as a Vector<T,T>
?
Is it possible?
Or is the only way of doing it is creating my own class which accepts lets say a String
and Number
in the constructor and create a Vector<T>
out of that class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,不符合标准。如果项目不是基本类型之一,您可以构建接口向量或超类。例如,包含 MovieClip 和 Sprites(两者都继承自 DisplayObject)混合的 DisplayObjects 向量。
例如:
在这种情况下,向量项将仅公开源自向量类型的自身属性和方法。但这正是您应该使用向量的原因,它确保您正在处理的项目类型。
我不知道你的具体情况或目标,但我会考虑为什么你需要向量中的混合类型。正如您所说,您的替代选择是创建一个包装类。下面的示例远未完成,但却是一个起点。
No, not by standard. If the items are not one of the primative types you can build a Vector of interfaces, or super classes. For example, a vector of DisplayObjects that contain a mixture of MovieClips and Sprites (which both inherit from the DisplayObject).
For example:
In this case the vectors item will only expose the properties and methods of itself that stem from the Vectors type. But this is exactly the reason you should use vectors, it ensures the items type you are handling.
I don't know your specific case or goal, but I would consider why you need a mixed type within a vector. Your alternative option, as you stated, would be to create a wrapper class. The example below is far from complete but a starting point.
你不能这样做,所以我会采纳你的建议,即创建一个包含两个属性(比如 Number、String)的特殊类,并创建一个它的 Vector。
You can't do that, so I would go with your suggestion, which is to create a special class containing two properties (say Number, String) and create a Vector of that.