Entry (main) method inside a class?

Benji Smith dlanguage at benjismith.net
Fri Mar 16 15:42:32 PDT 2007


Frits van Bommel wrote:
> Dejan Lekic wrote:
>> Is there particular reason why we are not able to have entry (main) 
>> method inside a class, like is possible in JAVA for an example?
>> Even though I am not a big JAVA fan, I must say I like that feature... :)
> 
> AFAIK the only reason Java has that "feature" is its complete inability 
> to have functions *outside* of classes :).
> 
> Though I could see uses for this, like to run unittests (similarly to 
> what running Python modules "stand-alone" often does).
> D has gone another way there though, using explicit unittest {} blocks. 
> Unfortunately, there is currently no way to run these separately (esp. 
> right after compilation) that I know of.

It can be convenient to package up a JAR file with multiple executable 
classes. Then you can run multiple different applications with the same 
binary just by passing a different app name on the commandline.

It doesn't really apply to D, though. Without a runtime classloader, it 
doesn't make any sense to have a single EXE with multiple entry points.

--benji



More information about the Digitalmars-d mailing list