我经常会想获取参数的实际类型,在Hibernate中就利用的这一点. domain: Person.java public class Person { // 编号 private Long id; // 姓名 private String name; public Person() { } public Person(Long id, String name) { this.id = id; this.name = name; } public Long getId() { return id…
public class Test<T> { private final TypeToken<T> typeToken = new TypeToken<T>(getClass()) {}; private final Type type = typeToken.getRawType(); public void foo() { System.out.println(this.type); } public static void main(String[] args)…