public static <T> List<T> listAndCast(Query query) {
@SuppressWarnings("unchecked")
List<T> list = query.list();
return list;
}
:誰かがこのJavaジェネリック構文を説明できますか?次の行で
public static <T> List<T> listAndCast(Query query) {
はなぜ<T>
が必要なのでしょうか?
残念ながら、これはプレーン 'List'を返す従来のAPIを扱うの少なくとも痛みを伴う方法ですが、あなたが本当にそれという_know_を'List'を返します。 –
mitchnull
私は@mitchnullに同意します。ここでも同じことが起こっています:http://stackoverflow.com/questions/115692/how-to-avoid-type-safety-warnings-with-hibernate-hql-resultsそしてここに起こっていることについての洞察をありがとう! – brainydexter
それはおそらく唯一の有効な使用 – dty