This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
I like your name!!!
Posted by Kishori Sharan on December 27, 2000 at 1:21 PM
Hi Saddy I like your name!!! Is it your real name? Here is the truth. When you call elements ( ) method on an object of Vector class then the elements ( ) method returns an anonymous class which implements Enumeration interface.Now you must be curious enough to know the declaration of that anonymous class. I have attached the implementation of elements ( ) method of Vector class at the end of this posting. So the code Enumeration e = v.elements ( ) ; is ok because at run time v.elements ( ) returns an object of a class which implements Enumeration interface. This can be proven by System.out.println ( e.getClass().getName ( ) ) ; which will print java.util.Vector$1 Since the anonymous class being used here is the first one used in Vector class , so is its name Vector$1. Thanx Kishori
////////////// elements() method of java.util.Vector class public Enumeration elements() { return new Enumeration() { int count = 0; public boolean hasMoreElements() { return count < elementCount; } public Object nextElement() { synchronized (Vector.this) { if (count < elementCount) { return elementData[count++]; } } throw new NoSuchElementException("Vector Enumeration"); } }; }
Replies:
|