java method that returns a generic type

Solutions on MaxInterview for java method that returns a generic type by the best coders in the world

showing results for - "java method that returns a generic type"
Mads
14 Aug 2016
1public static <T> T getRandomValue(List<T> listOfPossibleOutcomes, int numPossibilities) {
2    int r = RandomNumberGenerator.getRandIntBetween(0, numPossibilities);
3    return listOfPossibleOutcomes.get(r);
4}
5
6public static <T> T getRandomValueFromGenericList(List<T> list) {
7    Collections.shuffle(list);
8    return list.get(0);
9}