Here is an extremely simplyfied version of my recent project, which demonstrates the problem:
import java.util.List;
import java.util.ArrayList;
class Class{
List<Character> l1 = new ArrayList<>();
List<Character> l2 = new ArrayList<>();
List getList(){
return l1;
};
void setList(){
l2.clear();
l2.addAll(getList());
};
}
class Main{
public static void main(String[]args){
Class object = new Class();
object.setList();
};
}
When I compile it, the compiler says:
Note: Class.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
When I take l2.addAll(getList());
away, then the compiler doesn't return that message, but obviously this screws over my project.
What are unchecked or unsafe operations and how can I fix them?