Precedence of 'new' vs '.'
Nick Sabalausky
a at a.a
Tue May 5 16:29:55 PDT 2009
"Frank Benoit" <keinfarbton at googlemail.com> wrote in message
news:gtqf6c$8ma$1 at digitalmars.com...
> 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'm torn on this.
On one hand, I'm uncomfortable with having an operator that requires
whitespaces bind tighter than an operator that isn't typically used with
whitespace. To me, "new MyClass().run();" just *looks* like run() returns a
type and you're trying to instantiate *that* type (with a default
constructor).
But on the other hand, I can certainly see the practiclity of the Java
version and I've frequently had reason to use "(new MyClass()).run();" in my
own code.
More information about the Digitalmars-d
mailing list