User Profile

Collapse

Profile Sidebar

Collapse
nmb3000
nmb3000
Last Activity: Jun 8 '07, 03:00 AM
Joined: Mar 12 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • nmb3000
    replied to Get class name of instantiating class
    in Java
    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....
    See more | Go to post

    Leave a comment:


  • nmb3000
    replied to Get class name of instantiating class
    in Java
    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.
    See more | Go to post

    Leave a comment:


  • nmb3000
    started a topic Get class name of instantiating class
    in Java

    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());
      }
    }
    ...
    See more | Go to post
No activity results to display
Show More
Working...