groovy class vs script

已回答

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?

评论操作 固定链接

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.

def foo = new FoobarClass()
foo.greet()

class FoobarClass {
def greet() {
println("Hello World")
}
}

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?

 

0
评论操作 固定链接

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.

0

请先登录再写评论。