How to use a system call to find the name of my Java class

K

KO

I'm trying to have my program call itself to run another instance.
Basically, I want to dynammically find the name of my class to
implement this. I can get it to work if I update the name with the
new version of my code everytime but I want my code to be extendible
by other developers and still want to allow this functionality without
the other developers worring about updating this name everytime.
Please let me know if there is a system call which will allow me to
find the name of my class every time I run it. (I would think using
an argc or argv command would work but I'm getting weird results)


thanks!
-KO
 
J

Joona I Palaste

Sudsy said:
Which won't, of course, work in a static method like main...

Which won't be an issue, as in a static method the class name is known
at compile time...
 
T

Tony Morris

KO said:
I'm trying to have my program call itself to run another instance.
Basically, I want to dynammically find the name of my class to
implement this. I can get it to work if I update the name with the
new version of my code everytime but I want my code to be extendible
by other developers and still want to allow this functionality without
the other developers worring about updating this name everytime.
Please let me know if there is a system call which will allow me to
find the name of my class every time I run it. (I would think using
an argc or argv command would work but I'm getting weird results)

public class X
{
public static void main(String[] args)
{
Class c = X.class;
}

void m()
{
Class c = getClass();
}
}



Mind you, this appears to be a band-aid solution to what sounds like a
severe design deficiency.
i.e. your problem statement suggests a flawed approach to some bigger
problem (whose details have not been provided).

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top