Is it possible to avoid cast warnings after using createQuery().list?
//Type safety: The expression of type List needs unchecked conversion to conform to List<User>
List<User> user = (List<User>) session.createQuery("select u from User u").list();
I expected to find a method that specified the target object via generic parameter or method parameter such as the following:
List<User> user = session.createQuery("select u from User u").list(User.class);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…