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

Javac unable to resolve method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 8u20
    • Fix Version/s: None
    • Component/s: tools
    • Environment:

      Tested on an Ubuntu 14.04 install. `javac -version` outputs:

      javac 1.8.0_11

    • Subcomponent:
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Description

      Given the following Testcase:

      import java.util.Collection;
      import java.util.stream.Collectors;

      public class TestClass<E>
      {
          private Collection<E> coll;

          public void addAll(final Collection<? extends E> c) {
              coll.addAll(c.stream().collect(Collectors.toList()));
          }
      }

      My expected behaviour is for this to compile correctly, which it does in Java 8 u5 and u11. If you try and compile this class with javac from u20 then it is unable to find the collect() override correctly. Failing with the following error message.

      TestClass.java:9: error: no suitable method found for collect(Collector<Object,CAP#1,List<Object>>)
              coll.addAll(c.stream().collect(Collectors.toList()));
                                    ^
          method Stream.<R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super CAP#2>,BiConsumer<R#1,R#1>) is not applicable
            (cannot infer type-variable(s) R#1
              (actual and formal argument lists differ in length))
          method Stream.<R#2,A>collect(Collector<? super CAP#2,A,R#2>) is not applicable
            (cannot infer type-variable(s) R#2,A,CAP#3,T#2
              (argument mismatch; Collector<CAP#2,CAP#4,List<CAP#2>> cannot be converted to Collector<? super CAP#2,CAP#4,List<CAP#2>>))
        where R#1,T#1,E,R#2,A,T#2 are type-variables:
          R#1 extends Object declared in method <R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super T#1>,BiConsumer<R#1,R#1>)
          T#1 extends Object declared in interface Stream
          E extends Object declared in class TestClass
          R#2 extends Object declared in method <R#2,A>collect(Collector<? super T#1,A,R#2>)
          A extends Object declared in method <R#2,A>collect(Collector<? super T#1,A,R#2>)
          T#2 extends Object declared in method <T#2>toList()
        where CAP#1,CAP#2,CAP#3,CAP#4 are fresh type-variables:
          CAP#1 extends Object from capture of ?
          CAP#2 extends E from capture of ? extends E
          CAP#3 extends Object from capture of ?
          CAP#4 extends Object from capture of ?
      1 error

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                rwarburton Richard Warburton
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: