Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3706

"stream" should not be used for Collection "forEach" calls

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Drop this use of "stream()"; it is unneeded.
    • Highlighting:
      Hide

      stream()

      Show
      stream()
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      There's no need to invoke stream() on a Collection before a forEach call because each Collection has its own forEach method.

      Noncompliant Code Example

      identifiers.stream().forEach(System.out::println);  // Noncompliant
      

      Compliant Solution

      identifiers.forEach(System.out::println);  // Noncompliant
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: