A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/833 below:

[java] ForLoopCanBeForeach should consider iterating on `this` · Issue #833 · pmd/pmd · GitHub

Affects PMD Version: 6.0.0

Rule: ForLoopCanBeForeach

Description: The rule should report loops that are iterated on this if possible. For now it considers neither this.iterator() nor just iterator(). Followup on #800

Code Sample demonstrating the issue:

import java.util.Iterator;
class Foo<T> implements Iterable<T> {

  @Override
  public Iterator<T> iterator() {
    return null;
  }

  private void fofo() {
    for (Iterator<T> it = iterator(); it.hasNext();) {
      T item = it.next();
    }
    for (Iterator<T> it = this.iterator(); it.hasNext();) {
      T item = it.next();
    }
  }
}

Running PMD through: CLI


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4