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
-
Every time I try to install firefox on my laptop i get a message saying that the installation was interrupted. I am using windows 7.
Oh my god, thank you so much! Ive been working on this for hours and with your help it was done in five minutes. Thanks again!
-
I purchased a video from iTunes but it will not sync to my iPod. I get a message stating that the video "was not loaded to the iPod because iyt cannot be played on this iPod." I tried to use the "create an iPod version" but the command is grayed out
I was refering to the "sample rate", normally 44.1 KHz, the iPod might not be able to play tracks with a non-standard rate. Otherwise I'm not sure what the issue might be.
tt2 -
I found my old iPod that I haven't used since about 2010, and I no longer have the computer that the library was synced with. Is there any way to get my music off of it so that I can put it on my new iPod? The old one is a 30 GB from 2005.
CS2 is very old and reached its "end of life" a while back. So probably won't run on modern operating systems. If you can still run it, you'll need to uninstall what you have and re-install with the download link below to activate it.
Error: Activation Server Unavailable | CS2, Acrobat 7, Audition 3
Nancy O. -
I'm trying to update a Muse site and it keeps telling me that the site was created with a different version of Muse. I have updated Muse and still can't access the site to make changes.
Hi rgarden95,
Can you please confirm the exact version of Muse you are opening the file with?
To check the version of Muse, please click on help->About Adobe Muse CC.
Regards,
Akshay -
Knwoing the database was started with which pfile/spfile
hello to everyone,
Actually, a question that crossed my mind and I wondered if it's possible in Oracle.
For an already started database, is there a way to know the database was started with which pfile/spfile? Is there a view that tells this for example.
Many thnx.
H HiruyaIf spfile parameter is null, then you can look for a
pfile with the name convention of
init<ORACLE_SID>.ora.Yes, you can, but that won't tell you anything about which pfile was used to start the instance. I can just as easily type:
startup pfile=/my/pfile/that/does/not/conform/to/any/naming/standard
There's no way to definitively determine which pfile was used to start an instance.
-Mark -
Is anyone having same prob as me? I updated to 8.3 and lost photo stream on my photos - all my settings are set for photostream updating - the blue shirts at the Apple store seem to think that the feature was removed from the phones with the 8.1.3 update but it is not mentioned anywhere on Apple's site
found it
http://gimutaowebsolution.com/missing-photos-on-ios-8-3-or-8-x/ -
When trying to download podcasts to my ipod I get an error message that says the download was interupted and to push get button to resume. When I push the get button the same thing happens again and again. It never completes the download. What do I do?
See "Hang at exit":
*http://kb.mozillazine.org/Firefox_hangs
See "Firefox hangs when you quit it":
*https://support.mozilla.com/kb/Firefox+hangs
See also:
*https://support.mozilla.com/kb/Firefox+is+already+running+but+is+not+responding
*http://kb.mozillazine.org/Profile_in_use -
Trying to do the 5.1 I-phone 4 update
when I get to the end, I get an error message
"The iPhone :admin's iPhone" could not be updated because the firmware file is not compatible "
this is the only computer that has ever been used with this phoneHi Robertfrom Denver.
Did you try the solution given, and if yes, did it work?
I have done several "attempted downloads, and see the full file download, typically taking 30 minutes to complete, and then something goes wrong.
I am happy to suspend AV and FW software, but would like to know if it is a good fix or not first?
HelenfromBroughton Astley -
I just purchased an ITune gift card and when I enter it I am getting a message saying that it is an invalid code. what do I do?
Try here: iTunes Store: Invalid, inactive, or illegible codes.
tt2 -
Please help me to successfully install itunes updates. I have been unsuccessful every time I try!
What does the error message say? (Precise text, please.)
-
Transferred Itunes library from pc to new mac; however, when opening itunes on the new mac it reported that the library was created with a newer version of itunes and could not be opened. It asked if I wanted to download updates and I did. However, the new mac is up to date. Itunes won't open. What to do now? Any help would be appreciated.
Thanks
JimHello, Stephen.
Thank you for the question. You will need to rebuild your iTunes library file in order to open an older version of iTunes. Below, I have included the article that walks you through this process. Start with the section labeled Re-creating the iTunes Library file.
iTunes: How to re-create your iTunes library and playlists
http://support.apple.com/kb/ht1451
Cheers,
Jason H. -
I have all of my songs on an external hard drive. It was working fine with iTunes; now when I click on a song, I get an error message that the song cannot be located. What happended and more importantly, how can I fix this?
Is this an iPad issue? Not sure where you are "clicking" or how you are accessing. A little more info would help.
-
How do I upgrade the iOs on my ipad1 to version5? I've tried through itunes many times, but I get a message that says that the download was interrupted and i should try again later. Can i download the iOS file to my PC and transfer it to the ipad? How should I do that?
Thank you!
Disabling firewall and AV did the trick!
Kudos.
Alex -
When insert my lexar USB flash drive I get the message that the disk was not readable by this computer. It has worked previous to this and I do not want to lose the data by reformatting the drive. How can I reformat this drive and not lose my data?
You can't reformat it and not wipe everything on it.
Have you tried a different USB port?
Only other option, back it up on a different computer.
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
-
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