What does this mean: "from. <Integer>"?
I saw a question about Builder criteria and came up with this question ...
What does it mean from.<Integer> get("...?
I have never seen a point of expression <Integer>.
Can someone show me an example?
Link: Compile error when using CriteriaBuilder
Code:
public List<BankAccount> findWithBalance(int amount) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BankAccount> cq = cb.createQuery(BankAccount.class);
Root<BankAccount> from = cq.from(BankAccount.class);
ParameterExpression<Integer> balance = cb.parameter(Integer.class);
cq.select(from);
//Here is the trick!
Predicate predicate = cb.gt(from.<Integer> get("balance"), balance);
cq.where(predicate);
cq.orderBy(cb.asc(from.get("ownerName")));
TypedQuery<BankAccount> query = em.createQuery(cq);
query.setParameter(balance, amount);
return query.getResultList();
}
Thanks!
+4
3 answers
This is a call to the generic method c Integerpassed as a type parameter.
Look here:
Java syntax for explicitly describing common arguments in method calls
http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12
+4
Java Generics and Collections,
List<Integer> ints = Lists.<Integer>toList(); // first example
List<Object> objs = Lists.<Object>toList(1, "two"); // second example
In the first example, , Sun . toList , , , . ( Eclipse .)In the second example, . , Object , , Serializable Comparable. , .
:
, , , , ; , .
, , , .
Java , , . toList , , :
List<Integer> ints = <Integer>toList(); // compile-time error
, .
0