iterator() is listed as both instance method and abstract method of interface Iterable, like this:
Iterator<T> iterator()
Returns an iterator over elements of type T.
Returns:an Iterator
Under Abstract Method and Instance Method.
I thought an interface has 3 type of methods: default method, static method and abstract method; so my question is why is iterator() is a instance method under Iterable API ?
iterator() method API
Moderator: admin
-
- Site Admin
- Posts: 10398
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: iterator() method API
Not really sure what you mean. iterator() is indeed an abstract method in Iterable interface. See this: https://docs.oracle.com/javase/8/docs/a ... iterator--
If any non-abstract class (for example, ArrayList) says it implements Iterable, then it must provide an implementation of this method. In that case, it will be an instance method of that class.
If any non-abstract class (for example, ArrayList) says it implements Iterable, then it must provide an implementation of this method. In that case, it will be an instance method of that class.
Who is online
Users browsing this forum: No registered users and 2 guests