Please consider the following 3 Java classes:
Super class:
public abstract class Column<T>
{
private final Class<T> type;
private final String name;
public Column(Class<T> type, String name)
{
this.type = type;
this.name = name;
}
public Class<T> getType()
{
return type;
}
// ...
}
Working subclass:
public class FloatColumn extends Column<Float>
{
public FloatColumn(String name)
{
super(Float.class, name);
}
// ...
}
Problematic subclass:
public class ListColumn<L extends List<T>, T> extends Column<L>
{
public ListColumn(String name)
{
super((Class<L>) List.class, name);
}
// ...
}
The problematic subclass (ListColumn) compiles fine in Eclipse, with Java compiler compliance set to 1.6. However, when compiled through Maven (using the JDK compiler, with source and target set to 1.6), I get an Inconvertible types error at the super() call in the ListColumn constructor.
Edit: Eclipse does warn about this line (Type safety: Unchecked cast from Class<List> to Class<L>).
I know that Eclipse does not use the JDL compiler, and apparently the compiler it does use is less strict than the JDK one.
However, my question is how can I make this code work on the 1.6 JDK compiler.
In other words, how can a I call the super constructor with an argument that conforms to the expected Class<L> type where L is restricted to extends List<T>.
Preferably I only want to make changes in the ListColumn constructor, not in the Column class.
to Class* in Eclipse.
– Braj May 07 '14 at 19:34