Sunday, 5 May 2013

Why java has one public class per java file restriction?


It forces all Java code to be organized a certain way, which in the long run helps improve code readability. The Java designers chose a strict approach that enforces their idea of good design practices, and this is part of that theme.

Imagine you have a source file that references a lot of classes. If public classes were allowed to be defined in a file without name restrictions, you would have to inspect every file in every package until you find the correct definition. 

Right now the compiler only has to look for one file per package, and all files in the same package. That's a lot faster.

No comments:

Post a Comment