如何使用java反射来获取在类中定义的所有导入? [英] How to get all imports defined in a class using java reflection?
问题描述
我有一个类命名为SomClass.java,它导入一个名为SomPackage.RefClass的包以及一些其他java库,如java.lang ..等。 / p>
现在我想通过反思知道一个类中定义的所有导入。
import SomPackage.RefClass;
import java.lang.reflect.Field;
import java.io.IOException;
public class SomeClass {
RefClass refClass_Obj;
字符串国籍;
///一些其他成员
}
我只想知道使用反射定义在类中的所有导入的列表。
我看到一个问题发布听到类似于我的Q,但它没有很好地阐述所以,需要一些良好的方向帮助。
提前感谢。
我只想知道一个类中定义的所有
导入的列表,
反映
你不能因为编译器没有把它们放在目标文件中。它把它们丢掉。导入只是编译器的缩写。
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.
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.
这篇关于如何使用java反射来获取在类中定义的所有导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!