In Spring Data project the CrudRepository provides sophisticated CRUD functionality for the entity class that is being managed.
public interface CrudRepository<T, ID extends Serializable>
extends Repository<T, ID> {
<S extends T> S save(S entity);
T findOne(ID primaryKey);
Iterable<T> findAll();
Long count();
void delete(T entity);
boolean exists(ID primaryKey);
// … more functionality omitted.
}
In general, I know what "S extends T" means, i.e. that S, the return type of save operation, must be subtype of T. Why is it necessary to add such as constraint? I think that would be fine doing something like this:
T save (T entity);
As in
void delete(T entity);
I've googled to find more help and I've figured out following question on stackoverflow itself but it isn't really clear for me:
Spring CrudRepository: why to invent a new generic type S
thank you.
S
is redundant, and the signature design is a mistake. – ZhongYu