Why are interfaces in Java 8 allowed to have the main method?

前端 未结 5 1045
北荒
北荒 2020-11-29 06:10

Why are interfaces allowed to have a main method in Java 8?

As stated in below code it works fine and produces output properly.

public i         


        
5条回答
  •  感动是毒
    2020-11-29 06:58

    More of an addendum: maybe one thought here is to resemble what you can do with the Application trait in Scala:

    object Main extends Application {
      Console.println("Hello World!")
    }
    

    simply by extending Application, you turn a class into something that runs.

提交回复
热议问题