How does variable binding actually work in groovysh? -


here's crux of don't understand:

% groovysh groovy shell (1.8.6, jvm: 1.6.0_21) type 'help' or '\h' help. ------------------------------------------------------ groovy:000> class vars { groovy:001> static int x = 1; groovy:002> } ===> true groovy:000> println new vars().x 1 ===> null groovy:000> println vars.x error groovy.lang.missingpropertyexception: no such property: vars class: groovysh_evaluate possible solutions: class         @ groovysh_evaluate.run (groovysh_evaluate:2)         ... 

if vars resolves in expression new vars().x, why not in expression vars.x? it's phantom identifier exists purposes of instantiation.

your code doesn't work because using wrong naming conventions. should write class capital v. way groovy shell knows referring class, instead of variable, in case groovy cannot determine it.

this want:

groovy:000> class vars { groovy:001>     static int x = 1 groovy:002> } ===> true groovy:000> vars.x ===> 1 

hope helps!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -