-, raw Type PersonQueryBuilder . T , T? , :
PersonQueryBuilder<T> withName(String name);
PersonQueryBuilder<T> withAgeBetween(int from, int to);
, StudentRepository PersonQueryBuilder , :
interface UniversityRepository<T extends Student> extends PersonQueryBuilder<T> { }
, , StudentRepository UniversityRepository? - ? , , , , :
public interface StudentRepository<T extends Student> extends PersonQueryBuilder<T> {
@Override
StudentRepository<T> withName(String name);
@Override
StudentRepository<T> withAgeBetween(int from, int to);
StudentRepository<T> studying(Course course);
}
The obvious drawback of this approach is that you need to repeat all the inherited methods. You can get around this with the type parameter for the real repository:
public interface PersonQueryBuilder<T extends Person, R extends PersonQueryBuilder<T, R>> {
R withName(String name);
R withAgeBetween(int from, int to);
List<T> getResultList();
}
and
public interface StudentRepository<T extends Student, R extends StudentRepository<T, R> extends PersonQueryBuilder<T, R> {
R studying(Course course);
}
source
share