Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: Is Iterator a Class ?
|
Posted: Mar 5, 2004 10:05 AM
|
|
> Is Iterator a class?
When you compile the code for it, it produces a .class file.
But it is called an Interface.
List list = new ArrayList(); or ArrayList list = new ArrayList();
Iterator iterator = list.iterator(); ListIterator listIterator = list.listIterator();
Check out the documentation for Iterator, ListIterator , ArrayLiist, and List:
http://java.sun.com/j2se/1.4.2/docs/api/index.html
ArrayList is a Class List is an Interface ListIterator is an Interface Iterator is an Interface.
http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#238680
http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html
Excerpt from JLS: An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.
A nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface.
This chapter discusses the common semantics of all interfaces-top-level (§7.6) and nested (§8.5, §9.5). Details that are specific to particular kinds of interfaces are discussed in the sections dedicated to these constructs.
Programs can use interfaces to make it unnecessary for related classes to share a common abstract superclass or to add methods to Object. An interface may be declared to be a direct extension of one or more other interfaces, meaning that it implicitly specifies all the member types, abstract methods and constants of the interfaces it extends, except for any member types and constants that it may hide.
A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract methods specified by the interface or interfaces. A class necessarily implements all the interfaces that its direct superclasses and direct superinterfaces do. This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation.
A variable whose declared type is an interface type may have as its value a reference to any instance of a class which implements the specified interface. It is not sufficient that the class happen to implement all the abstract methods of the interface; the class or one of its superclasses must actually be declared to implement the interface, or else the class is not considered to implement the interface.
|
|