Ok, basicly I have created a Class.
And I have created a Vector and filled it with instances of this new class.
Now I want to traverse through the Vector (preferably efficiently) and run the method (doThis) on each element. This is what I have:
The problem is, the compiler is complaining that it can only return an 'object' from the iterator. So naturally I tried changing it to this:
This was wishfull thinking though, as now the next line is the problem, as obviously the Object Class doesnt have a doThis() Method.
So how can I cycle through the vector and run a method on each element?
Cheers, Josh
Code:
public class ClassX{ public ShapeObj(){} public doThis(){} }
Code:
Vector xv = new Vector(); xv.add(new ClassX()); xv.add(new ClassX()); xv.add(new ClassX()); xv.add(new ClassX());
Code:
ListIterator it = objlist.listIterator(); while(it.hasNext()){ [B][U][I]ClassX temp = it.next();[/I][/U][/B] temp. doThis(); }
Code:
ListIterator it = objlist.listIterator(); while(it.hasNext()){ Object temp = it.next(); [B][U][I]temp. doThis();[/I][/U][/B] }
So how can I cycle through the vector and run a method on each element?
Cheers, Josh
Comment