Le 16/10/2013 02:15, Richard Lee a �crit :
> I've got some code like this:
>
>
> class Foo
> {
> private var bar :Map = new Map<String, String>();
>
> public function new()
> {
> }
> }
>
>
> When I compile this, I get an error pointing the the declaration of
> variable 'bar' saying that it must be a constant value. I see no
> conceivable reason for this restriction. If it were, say, and 'inline'
> var, then, yes, I could see this being at the very most a warning, since
> you probably do not want to inline new, separate instances of the Map
> wherever 'bar' is used. But in this case, how is the above code any
> different than:
There is a potential user misunderstanding in what "var x = new Map()"
does when it's not static.
- some users might think that a new Map instance is created for each Foo
instance created.
- some users might think that the instance is shared between all Foo
instances (as it does for statics)
That's the reason we have forbidden non-constant member variable
initialization outside of the constructor.
Best,
Nicolas