Skip to content

Commit 0059e2d

Browse files
committed
exercise 8
1 parent d43fbd4 commit 0059e2d

File tree

1 file changed

+15
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)