Advertisement
Guest User

Untitled

a guest
Feb 9th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement