简体   繁体   English

在eclipse中我们可以从源代码中为java类生成main方法吗

[英]In eclipse can we generate main method for a java class from the source

When we create a new class file in eclipse the steps we follow is当我们在 eclipse 中创建一个新的类文件时,我们遵循的步骤是

  1. we name the class file我们命名类文件
  2. if we want a main class we click on the checkbox如果我们想要一个主类,我们点击复选框

    public static void main(String[] args)

But suppose we don't click the checkbox and create a .java file, is there a way to generate public static void main(String[] args) from the source, just like the way we generate getter/setter from source in eclipse.但是假设我们不点击复选框并创建一个 .java 文件,有没有办法从源代码生成public static void main(String[] args) ,就像我们在 eclipse 中从源代码生成 getter/setter 的方式一样。

PS: I know we can write public static void main(String[] args) manually, but I just want to know if eclipse has any feature to do that. PS:我知道我们可以手动编写public static void main(String[] args) ,但我只想知道 eclipse 是否有任何功能可以做到这一点。

You can write "main" and hit Ctrl + Space to generate the main method.您可以编写“main”并按Ctrl + Space以生成 main 方法。 In IDEA IntelliJ the alias is "psvm".在 IDEA IntelliJ 中,别名是“psvm”。

Eclipse does nothing you can't do your self just try it. Eclipse 不会做任何你自己做不到的事情,只要尝试一下。 Create a new class call it what ever you want then create public static method called main which has a return type of void and excepts String array and you are done here is an example创建一个新类,随心所欲地调用它,然后创建名为 main 的公共静态方法,该方法的返回类型为 void 和 String 数组除外,您在这里完成了一个示例

public class IWantCacke {

public static void main (String ...sdadasda){
    System.out.println("Welcome to my main");
}

} }

What youn need to understand that methods with the signature public static void main (String ...someArgName) are special methods that tell your program where to start you can create this method in any class it is static because it is born before any other object in your program您需要了解具有签名的方法public static void main (String ...someArgName)是特殊方法,它们告诉您的程序从哪里开始您可以在任何类中创建此方法它是静态的,因为它在任何其他对象之前诞生在你的程序中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM