Hello, I've been reading the Head First Design Patterns book and i've stumbled upon a problem. On the chapter about the iterators, i tried typing and compiling the code that the book gives, but i cant get it to compile.
Specifically I'm getting an error on: return new PancakeHouseMenuIterator(menuItems); this line in the end.
.\PancakeHouseMenu.java:26: cannot find symbol
symbol : constructor PancakeHouseMenuIterator(java.util.ArrayList<MenuItem>)
location: class PancakeHouseMenuIterator
return new PancakeHouseMenuIterator(menuItems);
Could somebody help me out with this one? I don't see what is wrong with it. By the way here's the PancakeHouseMenuIterator class, since i think it is pretty useful to help me resolving this problem.
If you need anything else please let me know, thanks in advance.
I am surprised to see that hasNext() method. It is bad style to write if (...) return true; else return false; or similar. It would have been better written it like this
Joined: Apr 15, 2011
I did try what you suggested, removing the void keyword from PancakeHouseIterator but then i get: PancakeHouseMenuIterator.java:8: invalid method declaration; return type required
Actually, I entered the void there, since I got this error, but i guess problems aren't that straightforward. About the other suggestion thank you, I didn't really put much thought in it, these examples are from the book, head first design patterns, so i just copied the code.
sorry didnt notice that the method signature was for PancakeHouseIterator not PancakeHouseMenuIterator.
change it to this:
If this is directly from the book, I'm surprised they missed this error.
Joined: Apr 15, 2011
Nop they didn't miss it, even though with the new version you do have to add the <MenuItem> on the ArrayList, since it was not needed for java 5 on which the book was published i think. But it was a typo error after all, instead of PancakeHouseMenuIterator I had PancakeHouseIterator...
God i hate when i look for a solution to such a problem for a long time Anyway, thank you very much for your input, greatly appreciated