我创建了以下类(class)。
public class SomeRequest<B extends Billing,E extends Employee, L extends Level>{
B billing;
E employee;
Class<L> level;
public void process(HashMap<String, Object> input){
this.billing = (B)data.get("billing");
this.employee= (E)data.get("employee");
this.level = (Class<L>)data.get("level");
//Some logic
}
}
在上面的类中,Employee
、Billing
和 Level
都是 Java POJO。
现在我如何实例化上面的 SomeRequest
类?
谢谢!
最佳答案
假设 SomeRequest
类有一个无参数构造函数
在 Java 7 中使用 diamond operator
SomeRequest<Billing,Employee,Level> instance = new SomeRequest<>();
在 Java 6 或 5 中
SomeRequest<Billing,Employee,Level> instance = new SomeRequest<Billing,Employee,Level>();
关于java - 实例化具有通用参数的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21773555/