是否可以在Java中定义以下内容:
public interface IGenericRepo<T> {
void add();
void delete();
void attach();
}
public interface IGenericRepo<Book> {
default String bookSpecificMethod(){
return "smthn";
}
}
public class NHGenericRepo<T> implements IGenericRepo<T>{
/* implementation */
}
public class NHUnitOfWork implements UnitOfWork{
@Autowired
public void setBookRepo(NHGenericRepo<Book> bookRepo) {
this.bookRepo= bookRepo;
}
public NHGenericRepo<Book> getBookRepo() {
return bookRepo;
}
private NHGenericRepo<Book> bookRepo;
}
并且能够在代码中的某个地方拥有:
{
@Autowired
public void setNhuw(NHUnitOfWork nhuw) {
this.nhuw = nhuw;
}
private NHUnitOfWork nhuw;
/**/
{
String st = this.nhuw.getBookRepo().bookSpecificMethod();
}
}
在 .net 中,可以通过使用扩展方法并将“this IGenericRepo
最佳答案
您能得到的最接近的是:
public interface IBookGenericRepo extends IGenericRepo<Book> {
void BookSpecificMethod();
}
关于java - Java 中的泛型特定接口(interface)定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23430685/