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

FP in S4276: interfaces with generic wildcard types can't be specialized

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.6
    • Component/s: Rules
    • Labels:
      None

      Description

      When an interface takes two generic wildcard types (i.e. "?"), it is not (always) possible to use a specialized Functional Interface instead.

      import java.util.function.Function;
      
      public class FunTypes {
          public static final Function<?, ?> NEW_OBJECT = anything -> new Object(); // FP
      }
      

      Message states:

      Refactor this code to use the more specialized Functional Interface ‘UnaryOperator<?>’

      It is not possible, the first "?" is not necessarily the same as the second "?".

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sebastian.hungerecker Sebastian Hungerecker
              Reporter:
              quentin.jaquier Quentin Jaquier
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: