Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

create and an enumeration of elements by instanting

Hi,
is possible to instantiate java.util.Enumeration with some elements at once?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You can't instantiate any kind of Enumeration - it's an interface
you must subclass it in order to do instantiating.

class YourEnumeration<E> implements java.util.Enumeration<E> {
      public boolean hasMoreElements() {
            // implement
      }

      public E nextElement() {
            // implement
      }
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What do you intend to do after instantiating an enumeration? An enumeration is not independent but is dependent over something (like a collection, over which it enumerates).

http://www.cs.wisc.edu/~solomon/cs537/java-tutorial.html
Avatar of komlaaa
komlaaa

ASKER

Thanks object, I am sure you mean something like:
Enumeration e = v.elements() ;
         
Mayankeagle:
>> What do you intend to do after instantiating an enumeration?
Well i had a method that takes an Enumeration as argument, that is after instantiating the enumeration, i will pass it to
the method i am not supposed to change.
>> that is after instantiating the enumeration,

You will not instantiate it. You will get it from something (like a collection) and then pass it to the method.