Extending a class with 'public static void main' no longer allows you to run it

In previous a IntelliJ version, it was possible to run a class which extended another with a `psvm` method. For example:

 

abstract class RunClass {
    static RunClass rc
    static void main(String[] args) {
         rc.run()
    }
    abstract void run() 
}

// Before, the IDE allowed you to run this class (green triangle on the left of the class name). 
class Test extends RunClass {
     static {  rc = new Test() }
     void run() {
          println “Hello World”
     }
}

I understand that the ‘main’ method is static and it should be executed from `RunClass` only, but I have an implementation in a library, in which an instance is passed to allow using a non-static method to be executed instead. 

Perhaps previous versions were mistaken (and current is the correct expectation) ?

0
2 comments

 

The JVM itself will not call a non‑static main, because it would require creating an instance of the class first, and the launcher has no mechanism for that. IntelliJ doesn’t override this rule; it only detects valid entry points and generates run configurations accordingly.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/17503872008466-InteliJ-forgot-shortcuts-again fnaf online

0

Please sign in to leave a comment.