Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. import java.util.List;
  4.  
  5.  
  6. //GENERIC class of W, but W is completely unused
  7. public class PlayExample<W> {
  8.  
  9.     public <T> T getFirstElement(List<T> list) {
  10.         return list.get(0);
  11.     }
  12.  
  13.     public static void main(String[] args) {
  14.  
  15.         List<Integer> list = new ArrayList<Integer>();
  16.  
  17.     //Now for some freaky weird magic. We parameterize PlayExample with ANY class.
  18.     //Doesn't matter at all which one.
  19.     //getFirstElement is now an Integer
  20.     //wtf?
  21.         new PlayExample<CompletelyMeaninglessClass>().getFirstElement(list);
  22.  
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment