www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inline New Class

reply "Malkierian" <rhydonj gmail.com> writes:
OK, so I don't even know what it's actually called, but for 
example, in Java:

exitItem.addSelectionListener(new SelectionAdapter() {

              Override
             public void widgetSelected(SelectionEvent e) {
                 shell.getDisplay().dispose();
                 System.exit(0);
             }
         });

You can create a new subclass of one you want to use in a 
function, with subclass function overrides such as this, but yet 
I can't seem to figure out how to do this in D.  The first 
bracket always has a red underline telling me it's expecting a 
')' (or a ';' in the case of trying to declare the listener 
before using it in addSelectionListener).
Mar 21 2014
next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Saturday, 22 March 2014 at 04:35:57 UTC, Malkierian wrote:
 OK, so I don't even know what it's actually called, but for 
 example, in Java:

 exitItem.addSelectionListener(new SelectionAdapter() {

              Override
             public void widgetSelected(SelectionEvent e) {
                 shell.getDisplay().dispose();
                 System.exit(0);
             }
         });

 You can create a new subclass of one you want to use in a 
 function, with subclass function overrides such as this, but 
 yet I can't seem to figure out how to do this in D.  The first 
 bracket always has a red underline telling me it's expecting a 
 ')' (or a ';' in the case of trying to declare the listener 
 before using it in addSelectionListener).
That does already exists in D.
Mar 21 2014
prev sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Saturday, 22 March 2014 at 04:35:57 UTC, Malkierian wrote:
 OK, so I don't even know what it's actually called, but for 
 example, in Java:

 exitItem.addSelectionListener(new SelectionAdapter() {

              Override
             public void widgetSelected(SelectionEvent e) {
                 shell.getDisplay().dispose();
                 System.exit(0);
             }
         });

 You can create a new subclass of one you want to use in a 
 function, with subclass function overrides such as this, but 
 yet I can't seem to figure out how to do this in D.  The first 
 bracket always has a red underline telling me it's expecting a 
 ')' (or a ';' in the case of trying to declare the listener 
 before using it in addSelectionListener).
http://dlang.org/class.html#anonymous The syntax is: new class SelectionAdapter { ... } BTW, you may find that digitalmars.D.learn is a better place to post questions.
Mar 21 2014
parent "Malkierian" <rhydonj gmail.com> writes:
On Saturday, 22 March 2014 at 04:45:44 UTC, Vladimir Panteleev 
wrote:
 BTW, you may find that digitalmars.D.learn is a better place to 
 post questions.
I knew that... I swear I did... XP
Mar 21 2014