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