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

Cannot choose between primitive and object variants of an overloaded method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.4.6
    • Static Type Checker

    Description

      The static type checked cannot choose which variant of a overloaded method with both primitive and object parameters (e.g. long and Long) to use when the actual type of the parameter is the object type (e.g. Long):

      class A {
          static String m(long p) {
              "primitive"
          }
      
          static String m(Long p) {
              "object"
          }
      }
      
      Long l = 42L
      A.m(l)
      

      yields the following compilation error:

      [Static type checking] - Reference to method is ambiguous. Cannot choose between [java.lang.String A#m(java.lang.Long), java.lang.String A#m(long)]
      

      The problem can be worked around by explicitely calling .longValue() on the Long.

      Attachments

        Issue Links

          Activity

            People

              pascalschumacher Pascal Schumacher
              fpavageau Frank Pavageau
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: