Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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);
}
Source by alvinalexander.com #
 
PREVIOUS NEXT
Tagged: #Java #method #returns #generic #type
ADD COMMENT
Topic
Name
2+6 =