Search code examples
javareflectiondependencies

How to get all imports defined in a class using java reflection?


Hi i am new in java reflection domain.So can anyone guide me in this problem scenario.

I have a class named "SomClass.java" and it imports a package named "SomPackage.RefClass" And some other java libraries like java.lang.. etc.

Now i wish to get know all the imports defined in a class through reflection.

import SomPackage.RefClass;
import java.lang.reflect.Field;
import java.io.IOException; 
 public class SomeClass{
  RefClass refClass_Obj;
  String nationality;
///some other members
}

I just wanna know the list of all import defined in a class using reflection.

I have seen a Question posted hear similar to my Q but it is not well elaborated so,need some good direction of help.

thanks in advance.


Solution

  • I just wanna know the list of all import defined in a class using reflection

    You can't because the compiler doesn't put them into the object file. It throws them away. Import is just a shorthand to the compiler.