如何让 Eclipse 为新的 Java 类自动生成 main 方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20726033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:48:43  来源:igfitidea点击:

How do you get Eclipse to auto-generate a main method for a new Java class?

javaeclipse

提问by

Does anyone know a reason why my Eclipse does not preload

有谁知道我的 Eclipse 没有预加载的原因

public static void main(String[] args)

when I create a new class? What can I do to make it appear automatically?

当我创建一个新类时?我该怎么做才能让它自动出现?

采纳答案by Paul Samsotha

"what can i do to make it appear automatically? "

“我该怎么做才能让它自动出现?”

  • Go to create New Java Class dialog
  • See a part that says "Which method stubs would you like to create?"
  • check public static void main(String[] args)
  • 转到创建新 Java 类对话框
  • 看到“您想创建哪个方法存根?”的部分。
  • 查看 public static void main(String[] args)

enter image description here

在此处输入图片说明

回答by Asheesh

Type mainand press ctrl+space. The eclipse content assist will pop up with main method. Press enter.

键入main并按ctrl+ space。eclipse内容辅助会弹出main方法。按enter

回答by zoladp

I think the best practise is to use only keyboard. It makes workflow a lot faster.

我认为最好的做法是只使用键盘。它使工作流程更快。

  1. Create new java class with Ctrl+n
  2. on dialog box, enter its (class) name
  3. use (left)Alt+vto easily tick checkbox for - public static void main(String[] args)
  4. then press [enter]Finish and voila class is ready...
  1. 创建新的java类 Ctrl+n
  2. 在对话框中,输入其(类)名称
  3. 用于(left)Alt+v轻松勾选复选框 -public static void main(String[] args)
  4. 然后按[enter]完成,瞧课程准备好了......