Skip to content

Instantly share code, notes, and snippets.

@niwinz
Last active December 22, 2015 10:49
Show Gist options
  • Save niwinz/6461676 to your computer and use it in GitHub Desktop.
Save niwinz/6461676 to your computer and use it in GitHub Desktop.
Why I cannot bind some class to one variable on groovy?
[3/5.0.2]niwi@localhost:~/Downloads/groovy-2.2.0-beta-2> ./bin/groovysh
Groovy Shell (2.2.0-beta-2, JVM: 1.7.0_40)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> class Foo {}
===> true
groovy:000> instance1 = new Foo()
===> Foo@6f24bcc6
groovy:000> cls = Foo
===> class Foo
groovy:000> cls
===> class Foo
groovy:000> new cls()
ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
groovysh_evaluate: 2: unable to resolve class cls
@ line 2, column 1.
new cls()
^
1 error
at java_lang_Runnable$run.call (Unknown Source)
@arturoherrero
Copy link

I think is a bug

Groovy Shell (2.2.0-beta-2, JVM: 1.6.0_51)
Type 'help' or '\h' for help.
----------------------------------------------------------------------------------------------------------
groovy:000> class Foo {}
===> true
groovy:000> cls = Foo
===> class Foo
groovy:000> cls.newInstance()
===> Foo@c1bb35b
groovy:000> new cls()
ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
groovysh_evaluate: 2: unable to resolve class cls
 @ line 2, column 1.
   new cls()
   ^

1 error

        at java_lang_Runnable$run.call (Unknown Source)

@glaforge
Copy link

glaforge commented Sep 6, 2013

No, it's not a bug, it's just not supported.
There were some historical reasons for that at the time we made that design decision, but the details escape me now.

@niwinz
Copy link
Author

niwinz commented Sep 6, 2013

Thanks for comments. But would be nice to use new in these cases too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment