Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 9th, 2013  |  syntax: Java  |  size: 0.80 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.Arrays;
  2.  
  3. /**
  4.  *
  5.  * @author Daniel Heinrich <dannynullzwo@gmail.com>
  6.  */
  7. public class Test<E extends Number> {
  8.  
  9.     void test1()
  10.     {
  11.         try{
  12.             E[] a = alloc(3);
  13.             System.out.println("test1 win");
  14.         }catch(Throwable t)
  15.         {
  16.             System.out.println("test1 fail");
  17.         }
  18.     }
  19.    
  20.     void test2()
  21.     {
  22.         try{
  23.             E b = null;
  24.             E[] a = alloc(3, b);
  25.             System.out.println("test2 win");
  26.         }catch(Throwable t)
  27.         {
  28.             System.out.println("test2 fail");
  29.         }
  30.     }
  31.  
  32.     public static <T> T[] alloc(int length, T... base) {
  33.         return Arrays.copyOf(base, length);
  34.     }
  35.  
  36.     public static void main(String[] args) {
  37.         Test<Integer> a = new Test<>();
  38.         a.test1();
  39.         a.test2();
  40.     }
  41. }
clone this paste RAW Paste Data