CriteriaBuilder has overloaded method isMember(...)
Create a predicate that tests whether an element is a member of a collection.
<E,C extends java.util.Collection<E>>
Predicate isMember(E elem, Expression<C> collection)
<E,C extends java.util.Collection<E>>
Predicate isMember(Expression<E> elem, Expression<C> collection)
I got ambiguous compilation error for the following call:
CriteriaBuilder.isMember((Expression<Object>)a, (Expression<Collection<Object>>)b);
The member type can be any, so it is Object type. How to fix it? Thanks.
You can declare an (unchecked) generic type to link the casts, perhaps in an internal private method to avoid it being visible to other callers. This even compiles:
CriteriaBuilder cb;
Object a;
Object b;
@SuppressWarnings("unchecked")
private <E> void isMember() {
cb.isMember((Expression<E>) a, (Expression<? extends Collection<E>>) b);
}
Though a and b would be better as type Expression, and/or as local variables or parameters in the method for more local scoping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With