This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Enumeration Interface Implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Enumeration Interface Implementation" Watch "Enumeration Interface Implementation" New topic
Author

Enumeration Interface Implementation

Pat Moran
Greenhorn

Joined: Feb 11, 2004
Posts: 20
I've got a simple program that processes all the elements of a Vector using an Enumeration. Since I am only USING the Enumeration interface and not IMPLEMENTing it, where EXACTLY are the abstract methods of the Enumeration interface "hasMoreElements()" and "nextElement()" implemented? I've tried looking through the docmentation, and I can't find where the actual implementation of the methods occur. ?!?
Thanks.
pm


pm
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
if you write something like:
System.out.println( new Vector().elements().getClass() );
the class name of the Enumeration will be displayed. In this case, it is: java.util.Vector$1.
What this tells you is that the implementation is an anonymous class declared within Vector.
A quick peek at the source of Vector.elements() reveals this to be the case.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Two notes:
1. Vector shouldn't be used. It's an old class kept around for backward compatibility. In many cases, an ArrayList is a good replacement.
2. I don't remember the reasons off hand, but folks recommend using an Iterator instead of an Enumeration.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enumeration Interface Implementation
 
Similar Threads
Implementation of Interfaces
Enumeration
Enumeration or instance methods
Implementatoion of hasMoreElemnts()???
doubt on Enumeration interface