Is it possible to put multiple groovy classes in the same groovy file?

You know, and I know that this can be done in Java, if only one is publicly available. But is it possible to do this in Groovy? And if so, under what conditions?

+6
source share
2 answers
public class A{ Integer a=2 } public class B{ Integer b=3+new CB().cb } private class CB{ Integer cb=2 } assert new A().a+new B().b==7 

Yes, you can put them all in one file and just use them the way you want in your main task ... or what do you mean by "conditions"?

+5
source

The differences between Java and Groovy in terms of classes that you can put in a single file:

  • MyFile.groovy can have several public classes, while MyFile.java can have only one
  • MyFile.java must have a class MyFile , whereas for MyFile.groovy
+7
source

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


All Articles