incubator-flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <>
Subject Re: Method overloading work-around: the problems & possible solution
Date Mon, 16 Jan 2012 18:15:07 GMT

On 1/16/12 9:30 AM, "David Arno" <> wrote:

> class TestAB
> {
>   public function testFoo():void
>   {
>     var ab:AB = new AB();
>;         // <- which foo does this call? int, uint or Number?
>;      // <- and this one? String or Object?
>     ab["foo"]("");     // <- how do we map this to ab.foo_String_void() ?
>   }
> }
If you are going to change the language, you might as well make it stricter
and report an error and ask for foo(int(i)) or foo(null as String).  I think
Java would report an error in this situation.
> I think the first problem (which method to use when the data is ambiguous)
> can be solved by a set of simple rules.
I would recommend some new global function called something like
getOverloadedMethodName("foo", ...) that takes the list of types or
parameters and computes the decorated name.  If the compiler can do it, we
can do it at runtime.  Also remember that in AS, a function call is a
shorthand for so I think there may always be use cases not
supported by the compiler.

> We put in place a catch-all foo that handles all the situations where the
> compiler cannot work out the mapping at compile time.
A catch-all will be slow and it is very easy to end up there since we don't
force strong-typing in the code.  Probably better to simply to be stricter
and simply not allow ambiguity.  You could also introduce a new keyword to
mark one method as the "default" or "catch-all"
> Thoughts?
> David.

Alex Harui
Flex SDK Team
Adobe Systems, Inc.

View raw message