[英]How can I rename my main class in the NetBeans IDE?
I am using NetBeans IDE and have created a new project.我正在使用 NetBeans IDE 并创建了一个新项目。 The new project includes a Main.java.新项目包括 Main.java。
Is it necessary to have it named Main.java, or can I rename the Main.java into another name?是否有必要将其命名为 Main.java,或者我可以将 Main.java 重命名为另一个名称吗? If so, how can I do this?如果是这样,我该怎么做? When I try to right-click Main.java, there is no rename option.当我尝试右键单击 Main.java 时,没有重命名选项。 I thought it was possible.我认为这是可能的。
There should be a menu item called应该有一个菜单项称为
Refactor --> Rename重构 --> 重命名
Link from NetBeans Wiki来自 NetBeans Wiki 的链接
Your name can be anything, as long as you have a你的名字可以是任何东西,只要你有一个
public static void main(String[] args)
in it (This is only if you want this class to be the entry point when you run your application).在其中(仅当您希望此 class 成为运行应用程序时的入口点时)。
You can call the file <whatever you like>.java
, but the name of the class in that file must match the new name you give to the file.您可以调用文件<whatever you like>.java
,但该文件中 class 的名称必须与您为该文件指定的新名称匹配。
So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main
to public class MyCoolClass
. So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main
to public class MyCoolClass
.
you can even have the simpler way,click on the file_name.java in the Projects panel,wait for a sec and click one more time (just as you rename any other folder/file).It will allow you to replace the new name and then it will popup a window asking whether you want to refactor or not...您甚至可以有更简单的方法,在“项目”面板中单击 file_name.java,等待一秒钟然后再单击一次(就像重命名任何其他文件夹/文件一样)。它将允许您替换新名称并然后它会弹出一个 window 询问您是否要重构...
you got to use the refractor, as it is the safest way to do such actions你必须使用折射镜,因为这是进行此类操作的最安全方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.