1 package com.xt.thinks15_7; 2 3 import java.util.Arrays; 4 5 class EraseObject1<A> { 6 7 } 8 9 class EraseObject2<A, B> { 10 11 } 12 13 class EraseObject3<K, V> { 14 15 } 16 17 /** 18 * 擦除测试 19 * 20 * @author Administrator 21 * 22 */ 23 public class ErasedTest { 24 public static void main(String[] args) { 25 EraseObject1<Integer> eo1 = new EraseObject1<Integer>(); 26 EraseObject2<Object, String> eo2 = new EraseObject2<Object, String>(); 27 EraseObject3<String, Integer> eo3 = new EraseObject3<String, Integer>(); 28 System.out.println(Arrays.toString(eo1.getClass().getTypeParameters())); 29 System.out.println(Arrays.toString(eo2.getClass().getTypeParameters())); 30 System.out.println(Arrays.toString(eo3.getClass().getTypeParameters())); 31 } 32 }
运行结果:
[A]
[A, B]
[K, V]
从运行结果可以看出这里new的新对象中的泛型类型在打印的时候是无法知晓被擦除了的