Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 12, 2016 Anonymous class | ||||
---|---|---|---|---|
| ||||
I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */ } }); I want to do this without making the things any complex. |
October 12, 2016 Re: Anonymous class | ||||
---|---|---|---|---|
| ||||
Posted in reply to tcak | On Wednesday, 12 October 2016 at 11:56:21 UTC, tcak wrote:
> I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes?
>
> public interface Runnable{
> void run();
> }
>
>
> runIt( new Runnable(){
> void run(){
> /* do stuff */
> }
> });
>
> I want to do this without making the things any complex.
Hmm. Yeah, after playing around, and some clues from net search. I found it.
runIt( new class Runnable{
void run(){
/* do stuff */
}
});
|
October 12, 2016 Re: Anonymous class | ||||
---|---|---|---|---|
| ||||
Posted in reply to tcak | On 10/12/2016 01:56 PM, tcak wrote: > I feel like I remember that this was added to D a while ago, but I am > not sure. Is it possible to create anonymous classes? > > public interface Runnable{ > void run(); > } > > > runIt( new Runnable(){ > void run(){ > /* do stuff */ > } > }); runIt(new class Runnable { void run() { /* do stuff */ }}); https://dlang.org/spec/class.html#anonymous |
October 12, 2016 Re: Anonymous class | ||||
---|---|---|---|---|
| ||||
Posted in reply to tcak | On Wednesday, 12 October 2016 at 11:56:21 UTC, tcak wrote:
> I feel like I remember that this was added to D a while ago
It has been there since the beginning, more or less, as long as I can remember.
|
Copyright © 1999-2021 by the D Language Foundation