I have a really simple groovy script-
import groovy.transform.Field
@Field final static String VARIABLE = 'Variable'
static void main(String[] args) {
println VARIABLE
}
But the output is empty, how can I make a global, static constant in groovy and use it in static methods?
to use a global static constant i would use this syntax - maybe not perfect but always working:
class Const{
final static String VARIABLE='value'
}
println "VARIABLE=${Const.VARIABLE}"
avoid using static void main() in groovy scripts - this way you could conflict with groovy script-to-class transformation
https://groovy-lang.org/structure.html#_public_static_void_main_vs_script
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