groovy class vs script
Answered
If I want to add some Groovy code, I have two choices. I can add a "Groovy Class" or a "Groovy Script". Is there any practical difference between these options?
Please sign in to leave a comment.
Hello,
Please check official documentation: https://groovy-lang.org/structure.html#_scripts_versus_classes
Let me be a little more clear. In IntelliJ IDEA, I can create a new "Groovy Class" or a new "Groovy Script" and this code works the same in both cases, AFAICT. I only have to make sure I don't have a name clash between my class and the "synthetic" class that is named after the file.
I'm wondering that the difference is between telling IDEA that I want a "class" file or a "script" file. Is there a difference in what will be compiled and when? Some difference in what can be imported into another file?
Chris,
Sorry, but it's not IDE file types. Those types come from language standard. Please check documentation - it describes differences between classes and scripts.