mardi 16 juin 2020

How do i get a property name instead of a property value? [duplicate]

I have this class:

public class Person {

    private String name;
    private int age;

}

I want to make an Excel file, and before I put the values into the Excel sheet i need name and age as columns in the sheet. All I need to know is how to get the property names (and NOT the values). So for example if i have:

name= "Marc"
age= 26

I want to get "name" and "age" first instead of "Marc" and 26. How do i do this? Just to be clear, the name and number of properties can vary so i can't hardcode "name" and "age", I need some way to iterate and get it. I know how to iterate and put it into the sheet. All i need help with is how to get the property name.

The closest i've got is getDeclaredFields(), but then i can't get further because I can't get anything from that Field type.





Aucun commentaire:

Enregistrer un commentaire