我可以编译一个名称与类不同的 java 文件吗? [英] Can I compile a java file with a different name than the class?
问题描述
有没有什么办法可以在没有java文件名及其基类名的情况下编译java程序.
Is there any way to compile a java program without having the java file name with its base class name.
如果是,请解释..
推荐答案
您的 Java 文件名应始终反映该文件中定义的公共类.否则,您将收到编译器错误.例如,test.java:
Your Java file name should always reflect the public class defined within that file. Otherwise, you will get a compiler error. For example, test.java:
public class Foo {}
尝试编译它会给出:
[steven@scstop:~]% javac test.java
test.java:1: class Foo is public, should be declared in a file named Foo.java
public class Foo {
^
1 error
所以你的文件名必须与你的公共类名相匹配,这似乎使你的问题没有实际意义.或者我不明白你在问什么......花一些时间解释你真正想要实现的目标会大大有助于提出一个更有效的问题:)
So you must have your filename match your public class name, which seems to render your question moot. Either that or I don't understand what you're asking... spending some time explaining what you are actually trying to achieve would go a long way towards asking a more effective question :)
这篇关于我可以编译一个名称与类不同的 java 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!