I’ve got java enums all over the place, and while I’ve seen various good ways of selecting ones at random, it feels like there should be a way to do this generically; that is, one method for selecting a random value from any supplied enum. Say,
public static <E> E randomMember(Enum<E> enumeration){
...
}
Yet I can’t figure out a way to do it, and the lack of Google results leads me to believe it isn’t possible (or isn’t a popular request, I guess).
Any thoughts?
You should be passing
enum‘s class, notenum‘s instance to get this to work: