Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3547

Improve rule S1612 to replace casts with method reference

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.10
    • Component/s: Rules

      Description

      Noncompliant Code Example

      list.stream()
        .map(a -> (B)a)  // Noncompliant
        .collect(Collectors.toList())
      
      

      Compliant Solution

      list.stream()
        .map(B.class::cast)  // Compliant
        .collect(Collectors.toList())
      
      

        Attachments

          Activity

            People

            Assignee:
            margarita.nedzelska Margarita Nedzelska
            Reporter:
            margarita.nedzelska Margarita Nedzelska
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: