Java泛型类<;界面>;
我创建了一个名为Identifier的接口。实现标识符接口的类是MasterEntitybean,如下所示Java泛型类<;界面>;,java,generics,Java,Generics,我创建了一个名为Identifier的接口。实现标识符接口的类是MasterEntitybean,如下所示 public class MasterEntity implements Identifier{ } dao.getEntity(MasterEntity.class); 在DAO方法中,我编写了一个方法,如下面的方法签名 public Identifier getEntity(Class<Identifier> classInstance){ } 但是我得到了一个错
public class MasterEntity implements Identifier{
}
dao.getEntity(MasterEntity.class);
在DAO方法中,我编写了一个方法,如下面的方法签名
public Identifier getEntity(Class<Identifier> classInstance){
}
但是我得到了一个错误,说-
The method getEntity(Class<Identifiable>) in the type ServiceAccessObject
is not applicable for the arguments (Class<MasterEntity>)
但是,通过指定可识别类型的类,如何实现它?将DAO方法签名更改为
public Identifier getEntity(Class<? extends Identifier> classInstance)
public Identifier getEntity(ClassTryClassI相信类型擦除是您第一次尝试失败的原因。但是您能解释一下为什么您认为需要将类类型信息传递到您的方法中吗?您是对的。它起作用了。非常感谢。
public Identifier getEntity(Class<? extends Identifier> classInstance)