[英]Object in Vector can't be converted to int
我有一个 function fillOval(int x, int y, int xSize, int ySize)
和一个包含 4 个Vectors
的数组,这些向量是用我的new2DVector
方法创建的。
但是,当我尝试这样做时:
for(Vector v : punkte) {
screen.fillOval(v.get(0), v.get(1), 60,60);
}
我收到一条错误消息,指出 v.get(0) 和 v.get(1) 是对象,无法转换为 int。
然后我尝试像这样添加一个标识符:
public Vector<int> new2DVector(int x, int y) { //<int> unexpected type error. required: reference
Vector v = new Vector(2);
v.add(x);
v.add(y);
return v;
}
但错误仍然存在。 我在这里做错了什么? 它不是这样工作的: Vector<int> v = new Vector(2);
任何一个。
您不能将原始类型int
用作泛型类型。 请改用Integer
。
the class Vector is a class generic, java not accept primitive types in class generics.
您可以使用参考类型 Integer。 ... public Vector new2D Vector(int x, int y)...
观察:Vector 被认为是过时的 class,根据您的需要寻找更好的替代品。
对不起我的英语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.