unexpected behavior in groovy compiler

View: New views
2 Messages — Rating Filter:   Alert me  

unexpected behavior in groovy compiler

by Sonny To :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

int i = 1
i = "abc"

compiling the above code with groovyc did not give a compiler error as
expected.  it compiles but does not run.
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException:
Cannot cast object 'abc' with class 'java.lang.String' to class
'java.lang.Integer'
        at foo.run(foo.groovy:2)
        at foo.main(foo.groovy)


Is this a bug or a feature? Seems like a bug to me because the
compiler should realize that i has been given declared as an int.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: unexpected behavior in groovy compiler

by Sonny To :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

oops sorry meant to post this on the groovy list

On Sun, May 4, 2008 at 3:30 PM, Sonny To <son.c.to@...> wrote:

> int i = 1
>  i = "abc"
>
>  compiling the above code with groovyc did not give a compiler error as
>  expected.  it compiles but does not run.
>  Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException:
>  Cannot cast object 'abc' with class 'java.lang.String' to class
>  'java.lang.Integer'
>         at foo.run(foo.groovy:2)
>         at foo.main(foo.groovy)
>
>
>  Is this a bug or a feature? Seems like a bug to me because the
>  compiler should realize that i has been given declared as an int.
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email