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

  • Home
  • SEARCH
  • 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 3873096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:59:50+00:00 2026-05-19T21:59:50+00:00

Using reflection you can get pretty much everything relating to a class. You can

  • 0

Using reflection you can get pretty much everything relating to a class. You can get all the declared methods, fields and classes (and possibly even more), but i couldn’t find a way to reflect on a method so i could find out what classes that method might be using.

Essentially i would like to find out all dependencies to other classes that a given class has.

Example:
Given the following code:

import com.yada.yada.yada.SomeClass 

public class MyClass
{
  public MyClass
  {
    new SomeClass();
  }
}

How can i find out that MyClass is using SomeClass in its constructor?

I was trying to think of a way to get all import statements defined in a class file but i couldn’t find anything that way either. But, assuming there’s a way to somehow dig up all import statements defined in a class file, how would one find out about classes defined in the same package, which do not require an import statement?

EDIT:

Scenario: The goal is to send the bytecode of this class (MyClass) to another process. This other process then takes in the bytecode and loads the class (MyClass) using class loaders, and so on. The problem is that when i try to create and run an instance of MyClass in the other process it fails because it cannot find a definition for SomeClass.

If SomeClass were a member of MyClass it wouldn’t be a problem but since the only reference to it lies in a method, there’s no way to get to it via reflection?

  • 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-19T21:59:50+00:00Added an answer on May 19, 2026 at 9:59 pm

    I think the closest you can come to getting all of a class’s dependencies is by hooking into the class loader mechanism and recording what classes get loaded when the class you’re examining is instantiated and its methods are called. Of yourse, you’d transitively also get all the classes that it indirectly depends on, but depending on what you want to do with the information, that may be what you actually need.

    But it’s impossible to do for all cases (just imagine a method that uses Class.forName() to ask for a random class name every time it’s called).

    how would one find out about classes defined in the same package

    That’s actually impossible to do in general, since the class loader concept really only allows asking for a fully qualified class name, and either getting that class or a ClassNotFoundException. Classes can be loaded from a webserver (in the case of applets) or generated on the fly, so you cannot know whether a specific class exists except by asking for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using reflection, how can I get all types that implement an interface with C#
Does creating an object using reflection rather than calling the class constructor result in
Is there a straightforward way using reflection to get at the parameter list for
So this seems pretty basic but I can't get it to work. I have
The reflection code below returns: System.Collections.Generic.IList`1[TestReflection.Car] Cars How can I get the Cars root
Using reflection, I need to investigate a user DLL and create an object of
Using reflection in .Net, what is the differnce between: if (foo.IsAssignableFrom(typeof(IBar))) And if (foo.GetInterface(typeof(IBar).FullName)
Using reflection on a method definition I would like to find out if the
I'm using reflection to loop through a Type 's properties and set certain types
Is there any way other than using reflection to access the members of a

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.