Precedence of 'new' vs '.'
Ary Borenszweig
ary at esperanto.org.ar
Tue May 5 18:43:54 PDT 2009
Frank Benoit escribió:
> In Java one can write:
>
> new MyClass().run();
>
> in D this does not compile, parenthesis are needed.
>
> (new MyClass()).run();
>
> But why is the D language designed like that?
I think it's because the (already hated by many, including myself)
ability to invoke a function (or a constructor) without parenthesis.
So:
new MyClass.run
and
new MyClass().run
should be the same, right?
But in the first case MyClass could be a package name and you are
constructing a new "MyClass.run" instance. You could make them behave
differently, but some would say it's not consistent, etc.
More information about the Digitalmars-d
mailing list