作为原始类型 'java.lang.Iterable' 的成员未经检查地调用 'forEach()'

Unchecked call to 'forEach()' as a member of raw type 'java.lang.Iterable'

我收到此编译器警告。 这是我的class使用的接口和方法(其他人员省略):

public class Controller extends BaseController {

//interface
public interface MyInterface<T extends Iterable<? super T>> {
    List<T> getList();
}

//method call
updateJoinTable(request.getProductGrades().size(), instance::getProductGrades);

//method
private 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 上看到了很多类似的案例,大部分是可比较的,我通过阅读解决方案了解到,这个问题是我的泛型类型绑定到一个本身有类型的类型,但我没有提供,所以它是原始的 - 然后我将该行添加到界面并期望警告消失。但它仍然存在。 你知道我应该怎么做才能摆脱它吗?

直接的问题是 MyInterface myInterface 是原始类型。使其成为非原始的,例如:

private static void updateJoinTable(Integer LastValidElement, MyInterface<?> myInterface) {

此外,您可能要考虑不使用 forEach。看起来你只是想砍掉列表的尾部:

List<?> list = myInterface.getList();
list.subList(LastValidelement, list.size()).clear();