Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. class GenericsTester {
  2.    public static void main(String[] args) {
  3.    
  4.     Box<Cake> cakeBox = new Box<>();
  5.     Box<Pie> pieBox = new Box<>();
  6.     Box<Tart> tartBox = new Box<>();
  7.    
  8.     cakeBox.put(new Cake());
  9.     pieBox.put(new Pie());
  10.     tartBox.put(new Tart());
  11.  
  12.    }
  13. }
  14.    
  15. class Box<T> {
  16.     private T t;
  17.  
  18.     public void put(T t) {
  19.         this.t = t;
  20.         }
  21.    
  22.     public T get() {
  23.         return t;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement