我可以编译一个名称与类不同的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屋!