Search code examples
javagenericsabstractraw-types

Collection of abstract generic class, raw type warning


I have following class hierarchy:

public abstract class Property<T>
{
    private long id;
    private String name;
    private T value;

    /*setters and getters*/
}

public class NumberProperty extends Property<Integer>

public class TextProperty extends Property<String>

...and a class containing List<Property> properties. I get "Property is raw type. References to generic type Property<T> should be parametrized". I know why, but I want to have one list of properties of few, known types (Property cannot be instatiated as it is abstract class).

My question is: can I ignore the warning or should I change my code (how?) ?


Solution

  • Use Property<?> if you don't care about which type of object it is this will instruct the compiler that you know what you are doing.

    List<Property<?>> list;