我有一个带有扩展 Paint 参数的泛型类。我真的不明白为什么我应该在第一个构造函数中手动将它转换为 T 。我究竟做错了什么?或者当编译器无法确定安全转换本身时就是这种情况?
public class XYPlot <T extends Paint> extends AbsPlot implements XYChartElement {
public XYPlot(AbsSeries series){
setUp(series, (T) new Paint(DEFAULT_PAINT));//TODO
}
public XYPlot(AbsSeries series, T paint){
setUp(series, paint);
}
private void setUp(AbsSeries series, T paint){
if(series == null) throw new NullPointerException("Series is null");
setSeries(series);
setPaint(paint);
}