ps-aux
ps-aux

Reputation: 12156

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?

Upvotes: 2

Views: 1922

Answers (2)

fram
fram

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

OldCurmudgeon
OldCurmudgeon

Reputation: 65811

You are probably looking for:

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

Upvotes: 4

Related Questions