📅  最后修改于: 2020-10-01 05:46:43             🧑  作者: Mango
可以使用以下java.lang.Class类的方法来显示类的元数据。
Method | Description |
---|---|
public Field[] getDeclaredFields()throws SecurityException | returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. |
public Constructor[] getDeclaredConstructors()throws SecurityException | returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. |
public Method[] getDeclaredMethods()throws SecurityException | returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. |
让我们创建一个类似于javap工具的程序。
import java.lang.reflect.*;
public class MyJavap{
public static void main(String[] args)throws Exception {
Class c=Class.forName(args[0]);
System.out.println("Fields........");
Field f[]=c.getDeclaredFields();
for(int i=0;i
在运行时,您可以获取任何类的详细信息,它可以是用户定义的或预定义的类。