SHARE
TWEET

generics example

DulcetAirman Feb 11th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top