Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8313448

incompatible types error on valid generics

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • 23
    • 8, 11, 17, 20, 21, 22
    • tools
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      Errors are displayed when compiling a valid code:

      java: incompatible types: cannot infer type-variable(s)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the attached class source

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code compiles without any problems
      ACTUAL -
      Compiliation error is displayed:

      InvalidGeneric.java:6:66
      java: incompatible types: cannot infer type-variable(s) InputType,OutputType
          (argument mismatch; BaseInput<capture#1 of ?,capture#2 of ?> cannot be converted to Input<InputType,OutputType>)
      InvalidGeneric.java:7:185
      java: incompatible types: cannot infer type-variable(s) InputType,OutputType
          (argument mismatch; BaseInput<capture#3 of ?,capture#4 of ?> cannot be converted to Input<InputType,OutputType>)

      ---------- BEGIN SOURCE ----------
      public class InvalidGeneric {

          public static void main(String[] args) {
              final BaseInput<?, ?> input = null;
              final Service service = new Service() {};
              final BaseInput.BaseOutput<?, ?> output = service.service(input);
              final BaseInput.BaseOutput<? extends BaseInput<?, ? extends BaseInput.BaseOutput<?, ?>>, ? extends BaseInput.BaseOutput<? extends BaseInput<?, ?>, ?>> output2 = service.service(input);
          }
      }

      interface Service {
          default <InputType extends Input<InputType, OutputType>, OutputType extends Input.Output<InputType, OutputType>> OutputType service(Input<InputType, OutputType> operation) {
              return null;
          }
      }

      interface Input<InputType extends Input<InputType, OutputType>, OutputType extends Input.Output<InputType, OutputType>> {
          abstract class Output<OutputType extends Input<OutputType, InputType>, InputType extends Output<OutputType, InputType>> {
          }
      }

      class BaseInput<BaseInputType extends BaseInput<BaseInputType, BaseOutputType>, BaseOutputType extends BaseInput.BaseOutput<BaseInputType, BaseOutputType>>
              implements Input<BaseInputType, BaseOutputType> {
          static class BaseOutput<BaseInputType extends BaseInput<BaseInputType, BaseOutputType>, BaseOutputType extends BaseOutput<BaseInputType, BaseOutputType>> extends Output<BaseInputType, BaseOutputType> {
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Declare variable as var or compile using eclipse compiler

      FREQUENCY : always


      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: