This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm having a real headache trying to understand why this is so, I probably Hello! I am getting totally confused but... After creating an ArrayList object and populating it with values using the add(Object o) method. I then iterate around the ArrayList by obtaining a ListIterator using the listIterator() method. Now ListIterator is an Interface according to the API, so how come you can call it's methods such as hasNext()?? Surely an interface has all abstract methods and therefore needs to be implemented by a concrete class?? Please help, I have a headache trying to figure this out.
Hi Chris, Welcome to JavaRanch! The listIterator() method returns an instance of a class that implements the ListIterator interface. A class that implements an interface can be passed as an argument of the interface type, or returned from a method as that interface, or assigned to a variable of that interface type. If you're curious as to the name of that class, try something like System.out.println(myArrayList.listIterator().getClass().getName());