-1

Suppose I have a vector my_vector, where I have 1 element of type Point

Vector my_vector = new Vector(); my_vector.addElement(Point(0, 0, 0))

And I have 1 variable of type Point

Point cur_point = new Point(0, 0, 0)

And I want to assign this variable to the first element of "my_vector". When I write

cur_point = my_vector.elementAt(0)

I have an error:

Incompatible types: Required: ClassName.Point Found: java.lang.Object

What should I do to have a vector of Point and have a possibility to take some element from it?

PepeHands
  • 1,368
  • 5
  • 20
  • 36

1 Answers1

3

You need to parameterize your Vector:

Vector<Point> my_vector = new Vector<Point>()

Alternatively you can cast the Object to a Point, but this is not as safe:

cur_point = (Point)my_vector.elementAt(0)

You should probably use an ArrayList instead of a Vector. See this question for more info.

Community
  • 1
  • 1
Mike B
  • 5,390
  • 2
  • 23
  • 45