Hmm, it seems we're just not connecting here.
I don't care what classes instantiate my class. What I want to do is from within *my* class, get the name of whatever class it was instantiated *from*.
So say I wrote Bar. You have a program named Bob. You instantiate Bar from within Bob. I want Bar to discover that your class is named Bob.
Is this possible? Thanks again....
User Profile
Collapse
-
Sorry, perhaps I wasn't very clear.
Foo in this case is a class I have no control over. I am writing Bar, and it will be instantiated as an object in Foo. I would like to know if there is a way that, from within Bar, I can find out what Foo's class name is.
Thanks again.Leave a comment:
-
Get class name of instantiating class
Java 1.5
I'm not sure if this is possible, but I'd like to get the class name of the class that instantiated my class. For example:
Code:public class Foo { public static void main(String args[]) { Bar b = new Bar(); } } ... public class Bar { public Bar() { System.out.println(parent.class.getName()); } }
No activity results to display
Show More
Leave a comment: