jeudi 17 décembre 2015

How can i get the name of a property by its value?

I have a class:

public class Something{
    public static final int SOMETHING_0 = 0;
    public static final int SOMETHING_1 = 1;
    public static final int SOMETHING_2 = 2;
    // ... etc
}

values are unique, How can i get the name of a property by its value?

via reflection, for example:

// intValue = 1
String getNameByValue(int intValue){
    ...
    // returns "SOMETHING_1"
    return nameOfProperty;
} 





Aucun commentaire:

Enregistrer un commentaire