Groovy static class

What does “static” do in this file, sample.groovy?

static class froob {
}

Groovy code compiles with or without static.

+3
source share
3 answers

There is absolutely no difference. Staticity is ignored in this situation.

To test, I created the groovy class and passed the file "javap -verbose StaticTest" to the file. Then put "static" in front of the def class and pass it to the second file. Then I split the two files. The only differences were those unique identifiers that are associated with a long class identifier, which is generated new for each class.

+5
source

"main" ?

"static" , , , . , "froob", , , .

. "" , "" , - .

+2

Java . Groovy 1.7 , .

In Groovy 1.7+, I expect static inner classes to have the same semantics as in Java. Declaring a top-level class is likely to have no effect (or be prohibited by the compiler).

+1
source

Source: https://habr.com/ru/post/1708098/


All Articles