import java.lang.reflect.Field;
public class Test { private String code; private String name; public void setCode(String code){ this.code = code; } public String getCode(){ return this.code; } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public static void main(String[] args) { Field[] fields = (new Test()).getClass().getDeclaredFields(); for(int i=0;i<fields.length;i++){ String varName = fields[i].getName(); System.out.println(varName); } } }
JAVA利用反射得到类的属性名称
最新推荐文章于 2023-07-22 19:15:26 发布