Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <A> List<A> flatten(List<List<A>> nestedLists);
  2.  
  3. flatten(nestedList.map(l -> l.map(any_function)))
  4. ≡ flatten(nestList).map(any_function)
  5.  
  6. <T> T broken { return new T(); }
  7.  
  8. void doStuff(List<Integer> collection) {
  9. }
  10.  
  11. void doStuff(List<String> collection) // ERROR: a method cannot have
  12. // overloads which only differ in type parameters
  13.  
  14. public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
  15.  
  16. public List<Integer> XXX(final List<Integer> l);
  17.  
  18. public <T> List<T> XXX(final List<T> l);
  19.  
  20. public class GenericClass<T>
  21. {
  22. private Class<T> targetClass;
  23. public GenericClass(Class<T> targetClass)
  24. {
  25. this.targetClass = targetClass;
  26. }
  27.  
  28. public T newT () {
  29. try {
  30. return targetClass.newInstance();
  31. } catch(/* I forget which exceptions can be thrown here */) { ... }
  32. }
  33.  
  34. private T value;
  35. /** @throws ClassCastException if object is not a T */
  36. public void setValueFromObject (Object object) {
  37. value = targetClass.cast(object);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement