The Enumeration interface includes a hasMoreElements() method, but not a
hasNextElement(). As to why hasNext() works: my guess is that the
implementation of Enumeration returned by the Hashtable also supports the
(preferred) Iterator interface.
-- Eric
On Fri, 18 Jan 2002, Steve Cohen wrote:
> All right, here is a distillation of what I thought was a stupid newbie
> question last night, but now I'm genuinely puzzled:
>
> >>> from java.util import Hashtable
> >>> h=Hashtable()
> >>> h
> {}
> >>> h.put("2","3")
> >>> h.put("1","2")
> >>> h
> {2=3, 1=2}
> >>> e=h.elements()
> >>> e
> java.util.Hashtable$Enumerator@5b5427
> >>> e.hasNextElement()
> Traceback (innermost last):
> File "<console>", line 1, in ?
> AttributeError: hasNextElement
> >>> e.hasNext()
> 1
> >>> e.nextElement()
> '3'
> >>> e.nextElement()
> '2'
> >>>
>
> h.elements returns a java.util.Enumeration
> That interface has hasNextElement() and nextElement() methods. It does
> not have a hasNext() method. Yet under jython, hasNextElement() is not
> recognized while hasNext() is recognized.
>
> What is going on here?
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|