嵌套类与单独的类文件 [英] Nested classes vs Separate class files
问题描述
p>好吧,如果你把所有的东西保存在同一个文件中,你会丢失包,private关键字不再有任何意义。
由于大多数Java项目将在一个IDE中打开,该IDE将不同的类显示为不同的选项卡,因此您可以在程序中加入更多的光标。
为什么会有同一个文件中的所有内容?
In java at least, my compiler won't let me put two (or more) separate classes in a single class file. It forces me to create multiple files in the same package. I understand why this is, and I agree with this principle. However, I've realized that I could just as easily nest the classes and contain the entire program (excluding imported libraries) in a single file. I would imagine that this would be frowned upon, but I don't understand why. What are the dangers and disadvantages of nesting class as opposed to the standard system (outside of the severe loss in organization and neatness)?
Well, if you keep everything in the same file, you lose packages and the private keyword does no longer have any meaning.
Given that most Java projects will be opened in an IDE that presents different classes as different tabs, you can have more that one cursor in the program.
Why would you have everything in the same file?
这篇关于嵌套类与单独的类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!