class GroovyHello {
public String execute() {
println("Test String is " + TEST)
}
private static final String TEST = "Test"
}
Output for the above snippet in Groovy V.1.6.3 is
Test String is Test
Output for the above snippet in Groovy V.1.8.6 is
Test String is null
The above snippet prints the string successfully if I modify the declaration to have either static (private static String TEST = "Test"
) or final (private final String TEST = "Test"
), but not both.
My theory that since object Static and Private then you don't have access to it as it is a separate object. However if it is just private then your method is part of the object and it has access to it. If it is just static then you have access to the field - the field is public by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With