• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Command pattern: Iterating over list of objects

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Afraid I've got lots of questions today. Following on from here here.

I'm using a LinkedList (correct choice?) to store a queue of instructions for my robot. The instructions are represented as objects like;



These get loaded into the LinkedList with the add method then I'm trying to read them out of the queue in the robots main run method like;



That results in a complain about "incompatible types" on this line "RobotInstruction Ri = It.next();".

How do you deal with this one? The examples I've found via Google so far have all involved casting the object returned from the Iterator to a String.

Many thanks again.
[ August 20, 2004: Message edited by: Daena Buyasta ]
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iterator returns Object when you call it.next(). You need to cast this into the appropriate class. In your case, casting it to
should work fine.
 
Daena Buyasta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect. Many thanks!

Have to say think RoboCode is a brilliant idea - this is the first I'm I've ever felt really motivated to do stuff with Java.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe LinkedList is usually the best Collection to use for a queue. Jakarta Commons Collections offers a Queue class, amongst others, if you want a closer fit.

Jules
 
I'm full of tinier men! And a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic