0

I'm not sure why my getIterator() function I made isn't working correctly. Below are the 3 classes I have and they implement each other. However specifically under the class MapView at the line Iterator gameObjects = gap.getCollection().getIterator(); the .getIterator() isn't getting the iterator from GameObjectCollection class like it should.

EDIT: The error it gives me is The method getIterator() is undefined for the type Object

Luigi
  • 4,129
  • 6
  • 37
  • 57
user2318083
  • 567
  • 1
  • 8
  • 27
  • 1
    i don't understand what is the problem, you get an error? a null? or what? – Marco Acierno Apr 20 '14 at 22:59
  • Sorry should've put the error in there. It gives me a `The method getIterator() is undefined for the type Object` – user2318083 Apr 20 '14 at 23:00
  • 1
    Shouldn't `GameWorldProxy` be a `GameObjectCollection` instead? That is the class you have shown which has the getIterator method in it. Does your class `GameWorldProxy` also have a getIterator method? – takendarkk Apr 20 '14 at 23:01
  • 1
    GameObjectCollection implements Collection, post GameWorldProxy too. – Marco Acierno Apr 20 '14 at 23:02
  • @Takendarkk that's what I thought too but I asked one of my classmates and he had it set up just like me, but his worked. But I'm gonna update the OP with `GameWorldProxy` – user2318083 Apr 20 '14 at 23:05
  • 1
    Alright, the object you are calling getIterator on is an instance of GameWorldProxy which _does not_ have a getIterator method. Did your classmate's GameWorldProxy also implement your Collection interface? In that case his would work because his class _would_ have this method in it. – takendarkk Apr 20 '14 at 23:07
  • Nope, his GameWorldProxy doesn't implement the Collection interface that's why I'm confused why it works. @Takendarkk – user2318083 Apr 20 '14 at 23:18
  • 1
    Without seeing his code it is pretty hard to tell exactly what the difference is between his and yours, but I can tell you 100% sure that if the class doesn't have the method in it, you can't call it. End of story. – takendarkk Apr 20 '14 at 23:21
  • @Takendarkk I agree with you. When I hover over the `.getIterator()` in Eclipse it shows `package.GameObjectCollection.getIterator()` then when I hover over `.getCollection()` it shows `package.GameWorldProxy.getCollection()` on his part. Not sure if this helps, maybe it can clear things up a bit on why his works and mine doesn't. – user2318083 Apr 20 '14 at 23:36
  • 1
    You get that error because GameWorldProxy's getCollection() returns type "Object". So there's no getIterator() on type Object. If you're sure it returns a different type, either change the return type (cast if needed) or cast the value you get in response and then call getIterator() on the correct type. – user1676075 Apr 21 '14 at 00:04
  • I figured it out, it was a simple mismatch of method names I had it on of the proxy strategies I used. – user2318083 Apr 21 '14 at 04:58

0 Answers0