Usage of static and final modifiers in Groovy-Collection of common programming errors
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.