Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6892825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:34:58+00:00 2026-05-27T06:34:58+00:00

I’m trying to find a way to list which objects a run-time object is

  • 0

I’m trying to find a way to list which objects a run-time object is referring to. I know there is a way to enquire the jvm using oql but what I’d like to do is to query it from inside a program. Is there any API I could use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:34:59+00:00Added an answer on May 27, 2026 at 6:34 am

    You can do it via Reflection (java.lang.reflect).

    How is described in this article. Basically, given this class that has private members:

    public class Secret {
    
        private String secretCode = "It's a secret";
    
        private String getSecretCode(){
            return secretCode;     
        }
    }
    

    With Reflection, you can access all of its members (including the private ones), including their values. And so you look at all of its data members to see what they refer to (and of course, you can repeat the process if they also refer to other objects). Here’s how to access their members (this code shows methods as well, which you probably won’t need if you’re just interested in data, but I didn’t see any good reason to pull that part out):

    import java.lang.reflect.Field; 
    import java.lang.reflect.Method; 
    import java.lang.reflect.InvocationTargetException; 
    
    public class Hacker {
    
        private static final Object[] EMPTY = {};
    
        public void reflect(Object instance)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            Class secretClass = instance.getClass();
    
            // Print all the method names & execution result
            Method methods[] = secretClass.getDeclaredMethods(); 
            System.out.println("Access all the methods"); 
            for (int i = 0; i < methods.length; i++) { 
                System.out.println("Method Name: " + methods[i].getName());
                System.out.println("Return type: " + methods[i].getReturnType());
                methods[i].setAccessible(true);
                System.out.println(methods[i].invoke(instance, EMPTY) + "\n");
            }
    
            //  Print all the field names & values
            Field fields[] = secretClass.getDeclaredFields();
            System.out.println("Access all the fields");
            for (int i = 0; i < fields.length; i++){ 
                System.out.println("Field Name: " + fields[i].getName()); 
                fields[i].setAccessible(true); 
                System.out.println(fields[i].get(instance) + "\n"); 
            }
        }
    
        public static void main(String[] args){
    
            Hacker newHacker = new Hacker();
    
            try { 
                newHacker.reflect(new Secret());
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    I’ve fixed a bug in their original code and made a small change to make it more clear that Hacker is not in any way tied to Secret (other than in main).

    Update: Re your question below about the fields from base classes, here’s an updated Hacker that does that (I’ve assumed you don’t want to try to enumerate the fields on Object, so I’ve stopped there):

    import java.lang.reflect.Field; 
    import java.lang.reflect.Method; 
    import java.lang.reflect.InvocationTargetException; 
    
    public class Hacker {
    
        private static final Object[] EMPTY = {};
    
        public void reflect(Object instance)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            Class cls = instance.getClass();
    
            while (cls != null && cls != Object.class) {
                System.out.println("From class: " + cls.getName());
    
                // Print all the method names & execution result
                Method methods[] = cls.getDeclaredMethods(); 
                System.out.println("Access all the methods"); 
                for (int i = 0; i < methods.length; i++) { 
                    System.out.println("Method Name: " + methods[i].getName());
                    System.out.println("Return type: " + methods[i].getReturnType());
                    methods[i].setAccessible(true);
                    System.out.println(methods[i].invoke(instance, EMPTY) + "\n");
                }
    
                //  Print all the field names & values
                Field fields[] = cls.getDeclaredFields();
                System.out.println("Access all the fields");
                for (int i = 0; i < fields.length; i++){ 
                    System.out.println("Field Name: " + fields[i].getName()); 
                    fields[i].setAccessible(true); 
                    System.out.println(fields[i].get(instance) + "\n"); 
                }
    
                // Go to the base class
                cls = cls.getSuperclass();
            }
        }
    
        public static void main(String[] args){
    
            Hacker newHacker = new Hacker();
    
            try { 
                newHacker.reflect(new Secret());
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    When combined with

    public class BaseSecret {
    
      private String baseSecretCode = "It's a base secret";
    
    }
    

    and

    public class Secret extends BaseSecret {
    
        private String secretCode = "It's a secret";
    
        private String getSecretCode(){
            return secretCode;     
        }
    }
    

    you get:

    $ java Hacker 
    From class: Secret
    Access all the methods
    Method Name: getSecretCode
    Return type: class java.lang.String
    It's a secret
    
    Access all the fields
    Field Name: secretCode
    It's a secret
    
    From class: BaseSecret
    Access all the methods
    Access all the fields
    Field Name: baseSecretCode
    It's a base secret
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.