Back to Intellij Community

GroovyNestedClassWithInstanceMainMethod

plugins/groovy/groovy-psi/resources/inspectionDescriptions/GroovyNestedClassWithInstanceMainMethod.html

2025.3-rc-2524 B
Original Source

Reports instance main methods that are declared inside nested classes.

The invocation of main method within nested classes is not handled directly by Groovy; however, it is possible by delegating the execution to Java. In such a scenario, the code will be executed successfully only if the Java version is enough. Consider the following example:

class Outer {
  static class Nested {
    void main() {
      println 'Hello from nested'
    }
  }
}

The code runs successfully with Java 25, but not with Java 17.