Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Enumeration or java.util.Iterator

 
Peter, McLaughlin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question RE: criteriaFind return type. Obviously the best solution would be to work to an interface, supporting maintenance and enhancement etc. Which would provide the better reference to a set of matching objects, if the underlying data storage type required significant design changes in its implementation. Coding for change is not an easy task. There are a few who would state that the java.util.Iterator interface would be better as the Java 2 platform java.util package heavily uses this. On the other hand the previous major release uses java.util.Enumeration. I would be grateful if anyone who has an argument for either would reply to this new topic.
Thanks in advance,
Peter Mc Laughlin
 
Gennady Shapiro
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
I dont think there is a fundamental difference between Enumeration and Iterator when it comes to element up/down casting. They both are just vessels that carry whatever object you may give them and change of type of element-object wil requere effort (big or small) regardless of the nature of the vessel.
As of java 2, there is little to none use of Enumeration in the standard Java packages since the use of Hashtable and Vectors has been eliminated or reduced to minimum. Java 2 bets on Maps and Collections as the new way of presenting groups of objects, and these interfaces provide Iterators as a standard way of stepping through the elements. I think that we may see Enumerators (as well as Hashtable and Vectors) deprecated soon because of their inconsistent API.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seconded. The Vectors, Hashtables and Enumerations you find throughout the Java API are leftovers from Java 1.1 (which is two major releases back - ancient history in the Java world). They should only be used in legacy code; the Java in General (intermediate forum) recently featured a discussion on the subject.
Unfortunately I don't see these legacy classes disappear anytime soon. They are still part and parcel of a few important Java APIs. For example, a Properties object is a Hashtable. Enumerations are all over the Servlet API. And so forth. Without doubt this is the reason why they have not been deprecated yet.
- Peter
 
Gennady Shapiro
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking since EJB 2.0 (specifically entity find()) replaced Enumeration interface with Collection , they might do the same with the Servlet spec next time they release a major upgrade. But, you are right Peter, there is way too much legacy code out there using Hashtables and Vectors to move away from it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic