mardi 26 avril 2016

Reflection class java

I have this two classes and i want that the second one (DocumentiDiIdentitaList) creates a list based on all the values of the variables declared in the first class(DocumentiDiIdentita)

Actually i got this code

public class DocumentiDiIdentita {

    public static final String CARTA_IDENTITA = "CI";
    public static final String CARTA_IDENTITA_AFTER_25_06_2003 = "CI_NEW";
    public static final String PASSAPORTO_CONSOLATO = "PC";
    public static final String PASSAPORTO_QUESTURA = "PQ";
    public static final String PASSAPORTO_ESTERO = "PE";
    public static final String PATENTE_MORIZZAZIONE = "PZ";
    public static final String PATENTE_PREFETTURA = "PT";
    public static final String PORTOARMI = "PM";
    public static final String PASSAPORTO="PA";

}

public static class DocumentiDiIdentitaList {
    private static Field[] fields = DocumentiDiIdentita.class.getFields();
    public static List documentTypes = Arrays.asList(fields);

}

but actually the list documentTypes cointains the name of the variables, not their values, so actually is:

CARTA_IDENTITA
CARTA_IDENTITA_AFTER_25_06_2003
PASSAPORTO_CONSOLATO
etc.

but i want:

CI
CI_NEW
PC
etc.

how can i do this? (i have to run on java 1.4)





Aucun commentaire:

Enregistrer un commentaire