Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将类型的向量实例化为子类型_Java_Object_Instance Variables - Fatal编程技术网

Java 将类型的向量实例化为子类型

Java 将类型的向量实例化为子类型,java,object,instance-variables,Java,Object,Instance Variables,如果我们有这些课程: abstract class Figure{ } class Cercle extends Figure{ } 如果我写: Vector<Figure> v = new Vector<Cercle>(); Vector v=new Vector(); 我有一个错误: incompatible types: Vector<Cercle> cannot be converted to Vector<Figure>

如果我们有这些课程:

abstract class Figure{
}

class Cercle extends Figure{    
}
如果我写:

Vector<Figure> v = new Vector<Cercle>();
Vector v=new Vector();
我有一个错误:

incompatible types: Vector<Cercle> cannot be converted to Vector<Figure>
不兼容类型:无法将向量转换为向量

如果有人知道它怎么不起作用,我很想知道为什么。谢谢你,对不起我的英语。

回答了很多次Java中的泛型类型不是协变的。

查看此链接。谢谢,这对我有帮助:)