// Guava 提供 TypeToken (基于反射获取泛型方法返回类型,ParameterizedType 表示 List<T>) TypeToken<List<String>> stringListToken = new TypeToken<List<String>>() {}; TypeToken<List<Integer>> integerListToken = new TypeToken<List<Integer>>() {}; TypeToken<List<? extends Number>> numberTypeToken = new TypeToken<List<? extends Number>>() {};
assertFalse(stringListToken.isSubtypeOf(integerListToken)); assertFalse(numberTypeToken.isSubtypeOf(integerListToken)); assertTrue(integerListToken.isSubtypeOf(numberTypeToken)); //an Integer class extends a Number class.
Copyright Declaration: This station is mainly used to sort out incomprehensible knowledge. I have not fully mastered most of the content. Please refer carefully.