Thanks for the replies. Let me explain the actual problem. I have a main method which reads a file and passes the data to a class whose name is a state code. ie AZ, DE,MA etc. Each of these state classes write out data that uses the state code. Each of these state classes is coded by a different person and currently they each have a statement in them that reads:
theState = "xx"; where xx is the name of the class. What I am trying to avoid is one of the programmers using the wrong state code when it is just the name of the class.
what I have come up with is the following method:
private static String myName()
{
String className;
int i = 0;
className = "A";
try
{
int ii = 1 / i;
}
catch (Exception e)
{
StackTraceElement[] se = e.getStackTrace();
String fullClassName = se[1].getClassName();
int lastDot = fullClassName.lastIndexOf(".");
className = fullClassName.substring(++lastDot);
}
return className;
}
Is there a simpler way of doing this. I look up reflection but couldn't figure out how to use it.
Thanks for any help.