Advertisement
DulcetAirman

generics example

Feb 11th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. package ch.claude_martin;
  2.  
  3. import java.util.*;
  4.  
  5. public class SomeClass {
  6.  
  7.     public static void main(String args[]) {
  8.         final class A<T> {
  9.             private T value;
  10.  
  11.             public A(T value) {
  12.                 this.value = value;
  13.             }
  14.  
  15.             public T getValue() {
  16.                 return value;
  17.             }
  18.         }
  19.  
  20.         A<? extends Number> a1 = new A<>(42);
  21.         System.out.println(a1.getValue());
  22.  
  23.         A<? super ArrayList<Integer>> a2 = new A<>(new LinkedList<Number>(Arrays.asList(1.2, Math.PI, -0)));
  24.         System.out.println(a2.getValue());
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement