komlaaa
asked on
create and an enumeration of elements by instanting
Hi,
is possible to instantiate java.util.Enumeration with some elements at once?
is possible to instantiate java.util.Enumeration with some elements at once?
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
}
}
class YourEnumeration<E> implements java.util.Enumeration<E> {
public boolean hasMoreElements() {
// implement
}
public E nextElement() {
// implement
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://www.cs.wisc.edu/~solomon/cs537/java-tutorial.html
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.
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.
You will not instantiate it. You will get it from something (like a collection) and then pass it to the method.