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

Ambiguous method exception when calling Math.min(), even with casts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-beta-7
    • None
    • None
    • Mac OS X 10.3.4, Java 1.4.2_03, Groovy 1.0-beta-5

    Description

      It seems that it is impossible to call Math.min() and similar methods that are overloaded with the same number of primitives. The following code snippets all fail with the same exception:

      minValue = Math.min(1, 2)
      minValue = Math.min(1.toInteger(), 2.toInteger())
      minValue = Math.min((int) 1, (int) 2)

      All of these result in:

      groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method: min. Cannot resolve which method to invoke due to overlapping prototypes between: [float, float] and: [double, double]

      This also makes it impossible to create java.awt.Color objects using RGB values, because Groovy cannot determine whether to use the float or int version of the constructor, regardless of the type of objects or casts being done.

      Attachments

        Activity

          People

            tug John Wilson
            marshall Marshall McMullen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: