我想我理解如何使用.class
和Class<>
但我猜不是。下面的super(ApprovalWorkstation.class
未映射到構造函數。我怎樣才能確定我傳遞了一個類引用,以便基地WorkstationRequest
可以實例化它?如何實例化一個通用類
public class ApprovalWorkstation extends Workstation {
public ApprovalWorkstation(WorkstationEntity entity) {
super(entity);
}
}
public class WorkstationRequest extends com.production.socket.request.WorkstationRequest {
public WorkstationRequest() {
super(ApprovalWorkstation.class); //unable to map to constructor
}
}
這是頭頂
public class WorkstationRequest {
private Class<Workstation> workstationClass;
public void WorkstationRequest(Class<Workstation> workstationClass) {
this.workstationClass = workstationClass;
}
更新
我的混亂對不起擴展底座WorkstationRequest
,我的構造函數實際上有Class<Workstation>
而不是Workstation
,我最初有。
'Workstation'和'類'不一樣的。目前還不清楚你想要做什麼。 –
2013-05-13 17:20:54
最後一段代碼錯誤,您無法將'Workstation'實例分配給'Class'變量。 –
hoaz
2013-05-13 17:21:42
難道你不能傳入一個對象,並從中獲得類? – christopher 2013-05-13 17:24:01