0

Here defined a doesn't print inside an method doit().

Integer a =0

void doit ()
{
    println a
}

May be i am stupid to ask it. Whats happening here ?

Bhanuchander Udhayakumar
  • 1,581
  • 1
  • 12
  • 30

1 Answers1

1

You need to make scope available for given method as follows,

import groovy.transform.Field
@Field Integer a = 1
void doit () { 
println a
}

doit ()​​​​​​​​​​​​

Read more : How do I create and access the global variables in Groovy?

Nitin Dhomse
  • 2,524
  • 1
  • 12
  • 24