java泛型——同一类型
作者:互联网
1.定义一个泛型类
class Box<T> { private T data; public Box() { } public Box(T data) { this.data = data; } public T getData() { return data; } }
2.测试,返回的class相同
@Test(timeout = 100) public void useAppContext() { Box<String> name = new Box<String>("corn"); Log.e(TAG, name.getData()); Box<Integer> age = new Box<Integer>(712); Log.e(TAG, name.getClass().toString()); // com.example.androidstudydemo.Box Log.e(TAG, age.getClass().toString()); // com.example.androidstudydemo.Box Log.e(TAG, (name.getClass() == age.getClass()) + ""); // true
标签:Box,getClass,Log,同一,TAG,泛型,java,data,public 来源: https://www.cnblogs.com/sunupo/p/15498265.html