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

Automatic Integer -> BigInteger coercion needed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-RC-1
    • None
    • None
    • Debian GNU/Linux Testing; Java 1.5.0_05; Groovy CVS 2005-11-16 14:47
    • Patch

    Description

      The statement:

      BigInteger i = new BigInteger ( "20" )

      works fine

      BigInteger i = new BigInteger ( 20 )

      fails with the message:

      Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.math.BigInteger(java.lang.Integer)

      since although there is a BigInteger ( int ) constructor there is no BigInteger ( Integer ) constructor and literals are Integer by default in Groovy. In fact, there seems no way of using an integer literal parameter as:

      BigInteger i = new BigInteger ( 20 as int )

      fails since the 20 as int appears to do nothing.

      It would be useful if

      BigInteger i = 20

      worked but currently this fails with:

      Caught: java.lang.ClassCastException: java.lang.Integer

      as there is no cast route from Integer to BigInteger.

      Attachments

        1. GROOVY-1141.patch
          3 kB
          codex22

        Activity

          People

            blackdrag Jochen Theodorou
            russel Dr. Russel Winder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: