Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11430

Inconsistent behavior when encountering overloaded methods

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.*;
      import java.util.function.*;
      
      class A<T> {
        void m(T x) { System.out.println("there"); }
        void m(Integer x) { System.out.println("here"); }
      }
      class Test {
        public static void main(String[] args) {
          A<Integer> x = new A<>();
          Consumer<Integer> y = x::m;
          y.accept(1)
        }
      } 

      Actual behavior

      Depending on the order in which methods "m()" appear in the program, the outcome is different. So, if "m( T x)" is first, the outcome is "there". Otherwise, if "m( Integer x)" is first, the outcome is "here".

      Expected behavior

      I would expect that the reference "x::m" is ambiguous, so the program should have been rejected.

      Tested against master (commit: d3c07b8416743545ebb81fda43768f2cec4ca59b)

      Attachments

        Activity

          People

            Unassigned Unassigned
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: