考虑以下MCVE:
public class MyClass {
private LinkedList<Foo> myList = new LinkedList<Foo>();
// Some irrevelant stuff which includes loading myList
public void myMethod() {
LinkedList<Foo> newList;
try {
newList = (LinkedList<Foo>) myList.clone();
} catch (ClassCastException e) {
// do something in case java screws up
}
}
}
我知道您可以通过使用来消除警告,@SuppressWarnings("unchecked")
但为什么该try/catch
块不起作用?放在那里是不是浪费时间和精力try/catch
?