1. 程式人生 > >使用反射繞過泛型,直接賦值

使用反射繞過泛型,直接賦值

public class GenericsTest {
 public static void main(String[] args) {
  ArrayList<String> collection1 = new ArrayList();
  collection1.add("abc");
  String str1 = collection1.get(0);
  System.out.println(str1);
  
  ArrayList<Integer> collection2 = new ArrayList();
  collection2.add(3);
  int int2 = collection2.get(0);
  System.out.println(int2);
 }