我有一个返回字符串列表的条件List<String>。
我有以下方法
return criteria.list();
但是代码显示
Type safety: Unchecked cast from List to List<String>
为了避免添加@SuppressWarnings("unchecked")
并确保类型被安全转换(不确定我是否应该这样做),我阅读了这个问题并尝试将解决方案添加到我的代码中
return Collections.checkedList(criteria.list(),List<String>);
但它显示另一个错误如下:
Multiple markers at this line
- Type safety: Unchecked cast from List to List<String>
- Syntax error on token ">", Expression expected after this
token
- 我不知道我是否真的应该使用 Collections.checkedList
- 如果我应该使用它,那么如何使用它?
谢谢