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

javac incorrectly complains of incompatible types

    XMLWordPrintable

Details

    • b120
    • Verified

    Description


      javac rejects code which is supposed to be compilable

      code sample:

      import java.util.function.Function;
      class Sample {
         public <T, R> void foo(Function<R, T> f1, Function<T, R> f2, R r) {}

         void m(Integer intValue) {
             foo(o -> o, o -> o , intValue);
         }
      }

      Error:
      C:\\Desktop\\Sample.java:6: error: incompatible types: cannot infer
      type-variable(s) T,R
      foo(o -> o, o -> o , intValue);
       ^
        (argument mismatch; bad return type in lambda expression
          Object cannot be converted to Integer)
      where T,R are type-variables:
        T extends Object declared in method <T,R>foo(Function<R,T>,Function<T,R>,R)
        R extends Object declared in method <T,R>foo(Function<R,T>,Function<T,R>,R)
      1 error



      Attachments

        Issue Links

          Activity

            People

              mcimadamore Maurizio Cimadamore
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: