Why doesn't ActionScript have “generics”?

前端 未结 4 1030
死守一世寂寞
死守一世寂寞 2020-12-18 18:14

Can anyone tell me why ActionScript 3, a statically typed language, doesn\'t have generics? Is it too much work? A historical thing? Is there some way to \"fake\" it that I

相关标签:
4条回答
  • 2020-12-18 18:44

    Parameteric types ( the word 'generics' is usually used in ECMAScript for generic methods, rather than the combination of parametric types and runtime polymorphism used in Java ) were proposed as part of ES4, but ES4 fractured and much of the type system proposed for ES ( including the parts implemented in ActionScript ) are not going into the next version. I can't say whether or not Adobe would want to go that way by themselves.

    0 讨论(0)
  • 2020-12-18 18:48

    Let's first get proper containers and algorithms in actionscript and then worry about generics...

    as3 is not very different from javascript, btw, so your question would kind of apply to JS as well.

    0 讨论(0)
  • 2020-12-18 19:02

    I believe it's a historical thing. ActionScript is based on ECMAScript (JavaScript is also based on ECMAScript). ECMAScript is a dynamically typed language, meaning that variables don't have their type declared. Generics are more useful in statically typed languages, wherein the type of variable is declared upfront. In a statically typed language, without generics you're stuck casting all the time from the root object (for example, Object in Java). This is not a problem in ECMAScript, because you can put anything you want into any data structure.

    So why didn't ActionScript add generics when they added static typing to ECMAScript? I can't be sure of that, but I think the premise of your question is a bit off - there are generic-esque containers, such as Vector. I might think they'd keep the dynamically-typed containers of ECMAScript (objects and arrays) for backwards-compatibility, but they already broke that between AS2 and AS3, so I'm not sure.

    0 讨论(0)
  • 2020-12-18 19:09

    The new Vector class is a form of generics that Actionscript 3 now supports when compiled for Flash Player 10. They don't support the specification of your own generic classes, yet.

    I think Adobe will implement the ES4 standard eventually. It would be nice if they had a competitor who could push them quicker in the right direction. I was expecting a little more from the updates to AS3 when they moved to CS4, but I suppose the revolutionary Vector class will have to suffice.

    It looks like they spent a lot of time beefing up the libraries for Flex and AIR, so maybe they'll go back to improving the language support later, but it probably isn't a real priority. Remember, Adobe is in it for the money, not for the feel good of making the sweetest possible language.

    0 讨论(0)
提交回复
热议问题