dimanche 29 décembre 2019

Select enum by ordinal; java

Is it possible to get an enum with its ordinal?

enum SimpleJackCards {
    As(11), König(10), Dame(10), Bube(10), Zehn(10), Neun(9), Acht(8),
    Sieben(7), Sechs(6), Fünf(5), Vier(4), Drei(3),Zwei(2), Yolly (1);
    private int value;
    SimpleJackCards(int val) {
        value = val;
    }
    int getValue (){
        return value;
    }
}

For example

I want to write a method that gives me a random card ... I would randomize an integer.

And want to get that enum with the generated ordinal number.

i.e.: ordinal value 0 would be enum As with value 11.




Aucun commentaire:

Enregistrer un commentaire