Я пытаюсь создать метод построения «вложенного» объекта Path. Я хочу что-то вроде этогоJPA Критерии Путь навигации
public Path<?> getPath(Path<?>path, SingularAttribute<?, ?>attribute) {
return path.get(attribute);
}
Но я получаю следующее сообщение об ошибке:
error: no suitable method found for get(SingularAttribute<CAP#1,CAP#2>)
return path.get(attribute);
method Path.<Y#1>get(SingularAttribute<? super CAP#3,Y#1>) is not applicable
(cannot infer type-variable(s) Y#1
(argument mismatch; SingularAttribute<CAP#1,CAP#2> cannot be converted to SingularAttribute<? super CAP#3,Y#1>))
method Path.<E,C>get(PluralAttribute<CAP#3,C,E>) is not applicable
(cannot infer type-variable(s) E,C
(argument mismatch; SingularAttribute<CAP#1,CAP#2> cannot be converted to PluralAttribute<CAP#3,C,E>))
method Path.<K,V,M>get(MapAttribute<CAP#3,K,V>) is not applicable
(cannot infer type-variable(s) K,V,M
(argument mismatch; SingularAttribute<CAP#1,CAP#2> cannot be converted to MapAttribute<CAP#3,K,V>))
method Path.<Y#2>get(String) is not applicable
(cannot infer type-variable(s) Y#2
(argument mismatch; SingularAttribute<CAP#1,CAP#2> cannot be converted to String))
where Y#1,X,E,C,K,V,M,Y#2 are type-variables:
Y#1 extends Object declared in method <Y#1>get(SingularAttribute<? super X,Y#1>)
X extends Object declared in interface Path
E extends Object declared in method <E,C>get(PluralAttribute<X,C,E>)
C extends Collection<E> declared in method <E,C>get(PluralAttribute<X,C,E>)
K extends Object declared in method <K,V,M>get(MapAttribute<X,K,V>)
V extends Object declared in method <K,V,M>get(MapAttribute<X,K,V>)
M extends Map<K,V> declared in method <K,V,M>get(MapAttribute<X,K,V>)
Y#2 extends Object declared in method <Y#2>get(String)
where CAP#1,CAP#2,CAP#3 are fresh type-variables:
CAP#1 extends Object from capture of ?
CAP#2 extends Object from capture of ?
CAP#3 extends Object from capture of ?
Любые предложения, как обойти эту ошибку? Большое спасибо.
UPDATE я найти быстрый обходной путь с вспомогательным методом:
public Path<?> getPath(Path<?> path, SingularAttribute<?, ?> attribute) {
return getPathHelper(path, attribute);
}
@SuppressWarnings("unchecked")
private <X, Y> Path<Y> getPathHelper(Path<X>, SingularAttribute<?, ?> attribute) {
return path.get((SingularAttribute<? super X, Y>) attribute);
}
Это работает, но этот код является правильным?
Пожалуйста, отправьте подпись метода 'Path.get', а также. –
@TanmayPatil Path.get имеет следующий signatute: http://docs.oracle.com/javaee/7/api/javax/persistence/criteria/Path.html#get(javax.persistence.metamodel.SingularAttribute) –