I want a generic method which fills a List with objects which are inherite from the class Element My code look like this:
public static <T extends Element> List<T> getElement(ElementType type){ List<T> elements = new ArrayList<>(); switch(type){ case LIGHT: elements.add(new Light(id,bezeichnung,beckhoffVars, false)); break; case LIGHTDIM: elements.add(new LightDim(id,bezeichnung,beckhoffVars, false, 0)); break; return elements; } But the Compiler says: The method add(T) in the type List is not applicable for the arguments (Light)
The method add(T) in the type List is not applicable for the arguments (LightDim)
public static List<Element> getElement(ElementType type)you are trying to use generics where you dont really need them