Currently I'm working on a service interface which retrieves domain objects based on a primary key. However I get the feeling I'm not efficiently using generics.
Base domain objects look as follows:
public interface DomainObject<PK extends Serializable> extends Serializable {
PK getID();
}
My service interface looks as follows:
public interface LoadService<T extends DomainObject<PK>, PK extends Serializable> {
T load(PK ID);
}
This works, however I have to specify the PK type in the service generics, even though the PK type is already known inside T. Is there any way I can get around having to define my PK again in the LoadService interface? Something like:
LoadService<T extends DomainObject<? extends Serializable as PK> { ... }
Help will be greatly appreciated!