How java uses reflection to get field names that use generics

public class  ClassA <T>{  
    private String name;
    private Object object;    
    private T obj;       
    public void setObject(Object object) {      this.object = object;  }     
    public Object getObject() {    return object;   }
    public void setObj(T obj) {   this.obj = obj;   }
    public T getObj() { return obj;   } 
    public void setName(String name) { this.name = name; }
    public String getName() { return name;  }
}

as ClassA above, because the generic symbol may not be T, how to get the field name obj through reflection?

Jun.07,2022

field name? Get it as much as you can. What does it have to do with field types

Field[] fields = ClassA.class.getDeclaredFields();
for (Field field : fields) {
    System.out.println(field.getName());
}
The field.getType () return of the

obj field is Object, which can be judged by this.


landlord, how did you solve this problem?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ef3f-2c45f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ef3f-2c45f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?