You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericMethods.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import java.util.*;
  2. /*
  3. * test case fodder for basic generic signature matching
  4. */
  5. public class GenericMethods {
  6. public List<Integer> returningListOfInteger() {
  7. return new LinkedList<Integer>();
  8. }
  9. public List<Object> returningListOfObject() {
  10. return new LinkedList<Object>();
  11. }
  12. public List returningRawList() { return new ArrayList(); }
  13. public LinkedList<Integer> returningSubtypeOfListOfInteger() {
  14. return new LinkedList<Integer>();
  15. }
  16. public void takesAMap(Map<Double,Short> aMap) {}
  17. public void takesAHashmap(HashMap<Double,Short> aMap) {}
  18. public static void staticTakesAMap(Map<Double,Short> aMap) {}
  19. public void collectionOfAnything(Collection<?> aCollection) {}
  20. public void collectionOfAnyNumber(Collection<? extends Number> aNumberCollection) {}
  21. public void collectionOfAnythingTakingADouble(Collection<? super Double> aDoubleHandlingCollection) {}
  22. // now some fun with statics
  23. static <T> T findMax(List<T> ts) { return ts.get(0); }
  24. static <T extends Comparable<T>> T betterMax(Collection<T> collection) {
  25. return null;
  26. }
  27. static <T extends Comparable<? super T>> T evenBetterMax(Collection<T> coll) {
  28. return null;
  29. }
  30. static <T extends Object & Comparable<? super T>> T jdkMax(Collection<? extends T> coll) {
  31. return null;
  32. }
  33. static <T> void copy(List<T> dest, List<? extends T> src) {}
  34. static <T,S extends T> copyv2(List<T> dest, List<S> src) {}
  35. }