This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question on Enumeration Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on Enumeration Interface" Watch "Question on Enumeration Interface" New topic
Author

Question on Enumeration Interface

sano vasu
Greenhorn

Joined: Mar 26, 2005
Posts: 8
suppose v is vector object with elements,

v.elements() returns the collection object of type Enumeration


Enumeration e = v.elements();


how can we request hasMoreElemets()and next() on e to retrieve the elements as Enumeration is an interface without implementation.
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
Actually, it will return to you a reference of some class that implements the Enumeration interface. This interface guarantees that whatever class it is, it implements the methods hasMoreElements() and next().

This is the power of programming to an interface. If someone comes up with the super data structure where everything is implemented in the best way possible, the designers of the Vector class can replace what they are using now and return the super data structure, and as long as it also implements Enumeration, it won't break your code.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Hi,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here. Thanks!


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on Enumeration Interface
 
Similar Threads
castNotSupportedException
where will be the method implementation present for an interface?
vector problem,how to retrieve data stored in vector and display in jsp pag
[Interview Q] Why does array index begin with 0 instead of 1 ???
Enumeration and Vector