Note that there are some explanatory texts on larger screens.

plurals
  1. POJava reflecting on method scope variables
    primarykey
    data
    text
    <p>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. </p> <p>Essentially i would like to find out all dependencies to other classes that a given class has. </p> <p>Example: Given the following code: </p> <pre><code>import com.yada.yada.yada.SomeClass public class MyClass { public MyClass { new SomeClass(); } } </code></pre> <p>How can i find out that MyClass is using SomeClass in its constructor? </p> <p>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? </p> <p>EDIT:</p> <p>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. </p> <p>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? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload