• Post Reply Bookmark Topic Watch Topic
  • New Topic

Enumeration Interface Implementation  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!