How to get name of class that the JVM was started with ?

Assume I have class foo with the standard main method.
I also have classes ding and dong, they extend foo.
The JVM is started with either ding or dong as the 'main' class. Since neither ding nor dong directly implement main, the actual main method being executed is foo's.
In the main method of foo I want to construct an instance of either ding or dong, depending on which the JVM was started with. Since I'm in a static context, I can't do anything with 'this'. Is there another way to get the name of the 'main' class from the JVM so that I can construct an instance of it ?

The idea behind all of this is that the developer of
Ding and Dong should not have to know anything about
foo, in particular it's constructors. But if Ding and Dong are subclasses of Foo, then developers must know about Foo. If you expect developers to extend a framework without having a well-defined interface to that framework, you are probably heading for trouble.
To be able to
privatize the constructors, construction of the
concrete class has to take place in foo.If Ding and Dong are subclasses of Foo, then you can not make all of Foo's constructors private.
Of course I could have a method in Ding and Dong that
calls a static method in foo into which the Ding and
Dong instance pass their class, but then I'd have
identical implementations of this method in Ding and
Dong. Yes you would (well, not identical, but very similar). Like I said, you could do this programmatically with AOP, or you could probably do it dirtily using stack traces (though with it being a single hit at startup, you might not consider it being quite so dirty).
But: the point of inheritance is that common
functionality goes into superclasses. I disagree. The important thing about inheritance is that classes share an interface, and that methods can be polymorphically inherited, allowing new functionality to be 'plugged in' in the future, and even at runtime.
Also, in
general one wouldn't make methods static if a class
reference is needed (or one would make it an
argument), but Sun didn't consult me when they
designed the main method :-(I still don't see why you need to do what you want to do. It appears that all you are after is the ability to start your program using a command line like
    java com.mypackage.Ding
instead of
    java com.mypackage.Foo com.mypackage.Ding
or
    java com.mypackage.Foo Ding.properties
or something else along these lines.
Since you must know the name of the class you want to use at the time you want to use it, why can't you just pass the name as an argument, or start up using some properties file, or a shell script?

Similar Messages

Maybe you are looking for

  • After 31.1.2 update cannot view new messages in pane or separate window

    Old messages before today appear, but any message wuht todays date does not appe, the view pane and the message window are blank. How can I move back to previous version until this is fixed?

  • Need help with embedded SWF Playing

    I have an embedded SWF file (A 4 photo slide show) created in Flash Professional CS5, Action script 3, flash player 10 selected. I have placed this into the flash catalyst CS5 file. The file previews in the browser perfectly. The problem is when publ

  • Bapi to update FB02 xref1 field

    Hi Experts, I need to update the xref1 field in FB02. Is there any BAPI to update? Thanks in advance.

  • Why "write configuration file (T)" on Close Config Data vi?

    If I open a config file refnum, write to one of its sections, then close the config refnum and have "write to configuration file (T)" set to FALSE, does the config file revert back to what it was when the refnum was first opened?  In other words, the

  • QuickTime 7.1 download

    My son downloaded iTunes 6 and was prompted to download a newer version of QuickTime. We uninstalled our older version of QuickTime and tried the free download of 7.1. When we click 'Save', QuickTime installer begins, but after the installer complete