Results 1 to 3 of 3
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Find instance that owns instance?

    Hai!
    I just wanted to know if you could, in some way, find that instance that have a varibale of another instance.
    For example:
    I have two classes, class_1 and class_2.
    class_1 have a variable named "class_2 foo;"
    foo is assigned to be = new class_2();
    Then I find the instance class_2, and I want to ask:
    Who have this instance of class_2 as a variable?

    Is it possible to find that out?

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    It is possible, but as a rule, it's really not what you want to do. If you're in a spot where you think you want to do that, you probably have problems with your overall design. But if you really want to do it, study about Reflection, and examining stack traces from within code.

    -Gary-

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Ahh riight!
    I'v heard of that :D
    Ohwell, I really dont need it, I just thought it might be easier, but
    because it seems not to, I will use another way around and look into how to use this cool methods later :D

    Thanks!

Similar Threads

  1. instance fields?
    By search4survival in forum New To Java
    Replies: 3
    Last Post: 04-03-2010, 06:10 PM
  2. Using an Instance method
    By Thumper in forum New To Java
    Replies: 4
    Last Post: 12-09-2009, 07:43 PM
  3. instance access
    By sujaiyer85 in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2008, 08:37 AM
  4. New Instance for SWT
    By srinivasa_v in forum SWT / JFace
    Replies: 1
    Last Post: 08-08-2007, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •