Reputation: 12156
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?
Upvotes: 2
Views: 1922
Reputation: 1621
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. Switching to 8 solved it for me.
Upvotes: 0
Reputation: 65811
You are probably looking for:
List<TableModel> list = Collections.<TableModel>unmodifiableList(tableModels);
Upvotes: 4