简体   繁体   English

通过Collections.unmodifiableList()删除警告产生

[英]Get rid of warning produces by Collections.unmodifiableList()

Following code produces this warning: 以下代码生成此警告:

Warning: 警告:

 Type safety: The expression of type List needs unchecked conversion to conform to List<TableModel>

Code: 码:

List<TableModel> tableModels = new ArrayList<TableModel>();
List<TableModel> list = Collections.unmodifiableList(tableModels);

The method signature is: 方法签名是:

public static <T> List<T> unmodifiableList(List<? extends T> list)

What am I missing? 我错过了什么?

您可能正在寻找:

List<TableModel> list = Collections.<TableModel>unmodifiableList(tableModels);

I was running into this issue when compiling code that I received from a colleague. 在编译我从同事那里收到的代码时,我遇到了这个问题。 Turns out I was using the Java 7 instead of Java 8 compiler. 事实证明我使用的是Java 7而不是Java 8编译器。 Switching to 8 solved it for me. 切换到8解决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM