Answers for "Java method that returns a generic type"

1

Java method that returns a generic type

public static <T> T getRandomValue(List<T> listOfPossibleOutcomes, int numPossibilities) {
    int r = RandomNumberGenerator.getRandIntBetween(0, numPossibilities);
    return listOfPossibleOutcomes.get(r);
}

public static <T> T getRandomValueFromGenericList(List<T> list) {
    Collections.shuffle(list);
    return list.get(0);
}
Posted by: Guest on April-27-2021

Code answers related to "Java method that returns a generic type"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language