Skip to content

Commit e8d1a30

Browse files
committed
Enums reusable class
1 parent eb6e448 commit e8d1a30

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

EnumaratedTypes/Enums.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Random;
2+
3+
public class Enums {
4+
private static Random rand = new Random(47);
5+
6+
public static <T extends Enum<T>> T random(Class<T> ec) {
7+
return random(ec.getEnumConstants());
8+
}
9+
10+
public static <T> T random(T[] values) {
11+
return values[rand.nextInt(values.length)];
12+
}
13+
14+
}

0 commit comments

Comments
 (0)