dimanche 27 septembre 2015

java: Is it possible to know which constructor an enumeration item uses to be initialized?

Just as the title say, I was wondering if it is programmatically possible to get to know the constructor that an enumeration item uses to be initialized, I think that if there is such mechanism it should be accessible by using reflection but I have not been able to find anything like that, to be more specific:

What I have

enum AnEnum {

    E1(1),
    E1(1, 2);

    int v;

    AnEnum(int p1) {
        v = p1;
    }

    AnEnum(int p1, int p2) {
        v = p1 + p2;
    }

} 

What I need is a mechanism to tell me whether the instance was initialized by using the one or the two argument constructor, and even better would be if I can get the parameters used to initialize it.





Aucun commentaire:

Enregistrer un commentaire