Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid type safety warnings with Hibernate criteria query

final Criteria crit = session.createCriteria(MyClass.class);
final List<MyClass> myClassList = crit.list();

results in this : Type safety: The expression of type List needs unchecked conversion to conform to List

Is their a method to remove the warning, as I get an error using this :

final List<MyClass> myClassList = Collections.checkedList(MyClass.class, crit.list());
like image 973
NimChimpsky Avatar asked Jan 26 '12 15:01

NimChimpsky


1 Answers

Well, you can use:

@SuppressWarnings("unchecked")

before the declaration...

Note that this will only suppress the warning - it won't do anything to make the code safer. In this case, I'd personally be happy enough about this; I'd trust Hibernate to do the right thing.

like image 196
Jon Skeet Avatar answered Oct 08 '22 03:10

Jon Skeet