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

method resolution not working

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.0-JSR-5
    • 1.0-RC-1
    • None
    • None
    • Mustang b82

    Description

      Caught: java.lang.ClassCastException: java.lang.Long cannot be cast to java.math.BigDecimal
      at Whole.<init>(testScript.groovy:37)
      at testScript.run(testScript.groovy:41)
      at testScript.main(testScript.groovy)
      Java Result: 1

      ----------------------------------------------------------------

      import java.math.BigInteger
      import java.math.BigDecimal

      class Rational {
      final BigInteger numerator
      final BigInteger denominator

      Rational(BigInteger numerator, BigInteger denominator) {
      def gcd = numerator.gcd(denominator)
      if (gcd > 0G)

      { numerator = numerator.divide(gcd) denominator = denominator.divide(gcd) }

      this.numerator = numerator
      this.denominator = denominator
      }

      Rational(BigDecimal number)

      { this(number.unscaledValue(), BigInteger.TEN.pow(number.scale())) }

      Rational(double number)

      { this(BigDecimal.valueOf(number)) }

      Rational(BigInteger number)

      { this(number, 1G) }

      }

      class Whole extends Rational {
      Whole(BigInteger number)

      { super(number) }

      Whole(long number) { super(number) }

      }

      x = new Whole(100)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            alexlamsl Alex Lam S.L.
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: