mirror of
https://github.com/github/codeql.git
synced 2025-12-30 23:58:15 +01:00
34 lines
1.5 KiB
XML
34 lines
1.5 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
|
|
<overview>
|
|
<p>
|
|
Java has two interfaces for dealing with iteration,
|
|
<code>Iterable<T></code> and <code>Iterator<T></code>. An
|
|
<code>Iterable<T></code> represents a sequence of elements that can be
|
|
traversed, and an <code>Iterator<T></code> represents the
|
|
<strong>state</strong> of an ongoing traversal. As an example, all the
|
|
<code>Collection<T></code> classes in the Java standard library implement
|
|
<code>Iterable<T></code>. Comparing this to a traditional
|
|
<code>for</code> loop that increments an integer index and iterates over the
|
|
elements of an array, then the <code>Iterable<T></code> object
|
|
corresponds to the array, whereas the <code>Iterator<T></code> object
|
|
corresponds to the index variable.
|
|
</p>
|
|
<p>
|
|
Implementations of <code>Iterable<T></code> are generally expected to
|
|
support multiple traversals of the element sequence they represent, although
|
|
there can be exceptions if the underlying data somehow makes this undesirable,
|
|
see for example <code>DirectoryStream<T></code>. If an implementation of
|
|
<code>Iterable<T></code> does not support multiple iterations, then its
|
|
<code>iterator()</code> method should throw an exception on its second and
|
|
subsequent calls. This makes bugs easier to find if such an
|
|
<code>Iterable<T></code> is used more than once, for example in two
|
|
different for-each loops.
|
|
</p>
|
|
</overview>
|
|
|
|
</qhelp>
|