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?
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With