I have this two interfaces and classes:
public interface Identifiable {
T getId();
}
public interface GenericRepository
I don't think you can omit it. With T extends Identifiable
you want to say that the generic type parameter must be an Identifiable
. Since Identifiable
is a generic class, you need to mention its generic type parameter too (if you want to play by the rules that is - if you omit it, you lose all generic type safety for GenericRepository
, due to backward compatibility rules). Note also that K
is actually used as the parameter type of GenericRepository.get
. And since that type may be different from T
, you need to satisfy the compiler by declaring it as another generic type parameter of GenericRepository
. Otherwise the compiler has no way of knowing what K
is.