• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

about methods in interface

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In java.Util package , there is an interface called Iterator..

the hasNext() and some more methods in Iterator interface are supposed not to be defined in interface..
they must be defined by concrete class which implements it...

how is it defined in interface?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The methods (hasNext() , next() and remove() ) are not defined in the interface. They are merely declared there.

Its implemented by other collection classes which have methods with return type as Iterator.
For example the AbstractList implements it and returns the Iteraror objec tin repsonse to iterator() method call.
 
Arun Prasath
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the class (LinkedHashSet), which implements interface iterator,there is no defined hasNext() method ..

how does the interator reference, which is assigned by ob.iterator(), get the hasNext() method in ipmlemented class?
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It implements the Iterable interface - not the Iterator interface.
All interfaces should be abstracted back to a type that contains all referentially transparent operations. This is often referred to as "immutable". Iterable is "immutable", Iterable is not; this allows Iterable to be used in the for each loop.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LinkedHashSet does not implement Iterator. The object that gets returned by LinkedHashSet.iterator() implements Iterator, but that's not a LinkedHashSet.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic