Eclipse warning - Class is a raw type. References to generic type Class<T> should be parameterized
18,151
Solution 1
I suspect its complaining that Class is a raw type. You can try
private List<Class<?>> classes;
or suppress this particular warning.
I would ignore the warning in this case. I would also consider using a defensive copy.
private final List<Class> classes = new ArrayList<>();
public List<Class> getClasses() {
return classes;
}
public void setClasses(List<Class> classes) {
this.classes.clear();
this.classes.addAll(classes);
}
Solution 2
Try
public class ListOfClasses
{
private ArrayList<Class<?>> classes;
public ArrayList<Class<?>> getClasses()
{
return classes;
}
public void setClasses(ArrayList<Class<?>> classes)
{
this.classes = classes;
}
}
Class is a parameterized type as well, and if you do not declare a type argument, then you get a warning for using raw types where parameterized types are expected.
Author by
CodeBlue
Updated on June 15, 2022Comments
-
CodeBlue almost 2 years
import java.util.ArrayList; public class ListOfClasses { private ArrayList<Class> classes; public ArrayList<Class> getClasses() { return classes; } public void setClasses(ArrayList<Class> classes) { this.classes = classes; } }
For this, I get the following warning in eclipse -
Class is a raw type. References to generic type Class should be parameterized
This was asked in an earlier question, but the answer was specific to the Spring Framework. But I am getting this warning even without having anything to do with Spring. So what is the problem?