我收到此编译器警告。这是我使用的接口和方法的类(其他人员省略):public class Controller extends BaseController {//interfacepublic interface MyInterface<T extends Iterable<? super T>> { List<T> getList();}//method callupdateJoinTable(request.getProductGrades().size(), instance::getProductGrades);//methodprivate static void updateJoinTable(Integer LastValidElement, MyInterface myInterface) { myInterface.getList().subList(LastValidElement, myInterface.getList().size()) .forEach(i ->myInterface.getList().remove(i));}}forEach 的最后一部分引起警告。现在,起初代码没有:<T extends Iterable<? super T>>但是我在 SO 上看到了很多类似的案例,主要是具有可比性,我通过阅读解决方案了解到,这个问题是我的泛型类型绑定到一个本身有类型的类型,但我没有提供一个,所以它是原始的 - 然后我将该行添加到界面并预期警告消失。但它仍然存在。你有什么想法我应该怎么做才能摆脱它?
1 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
直接的问题是这MyInterface myInterface是一个原始类型。使它成为非原始的,例如:
private static void updateJoinTable(Integer LastValidElement, MyInterface<?> myInterface) {
此外,您可能需要考虑不使用forEach. 看起来你只是想砍掉列表的尾部:
List<?> list = myInterface.getList();
list.subList(LastValidelement, list.size()).clear();
添加回答
举报
0/150
提交
取消