Suggestion: Change precedence of 'new'

Bill Baxter dnewsgroup at billbaxter.com
Thu Apr 10 09:30:00 PDT 2008


Georg Wrede wrote:
> Bill Baxter wrote:
>> Robert Fraser wrote:
>>
>>> Unknown W. Brackets wrote:
>>>
>>>> I think the problem is in supporting this syntax:
>>>>
>>>> auto x = new package.module.Class;
>>>
>>>
>>> The argument (as far as I can tell) is that it would be supported 
>>> only if trailing parentheses were supplied, so that expression would 
>>> have to be written as "new package.module.Class().propertyMethod;".
>>
>>
>> That makes sense.  So the rule would be that 'new' munches all the 
>> dot-separated identifiers to its right till it hits something besides 
>> a dot or an identifier.
>>
>> Here's another one from actual D code ported from Java:
>>
>>     (new class Runnable {
>>         public void run() {
>>             if (canvas.isDisposed()) return;
>>             render();
>>             canvas.swapBuffers();
>>             canvas.getDisplay().timerExec(15, this);
>>         }
>>     }).run();
>>
>> In Java the parens around that whole mess aren't necessary.
> 
> Just to clarify, how would that look with the proposed precedence?

You mean what does it look like in java?  Like this:

      new class Runnable {
          public void run() {
              if (canvas.isDisposed()) return;
              render();
              canvas.swapBuffers();
              canvas.getDisplay().timerExec(15, this);
          }
      }.run();

(it's creating an anonymous subclass of 'Runnable', and running it.)

--bb



More information about the Digitalmars-d mailing list