It seems to me that non-public top-level classes and static nested classes essentially perform the same tasks when creating a helper class.
A.java
public class A
{
public static main (String[] args)
{
AHelper helper = new AHelper();
}
}
class AHelper {}
A.java
public class A
{
public static main (String[] args)
{
A.AHelper helper = new A.AHelper();
}
static class AHelper {}
}
Aside from how they are referenced, there seems to me very little difference between the two ways of creating a helper class. It probably comes down mostly to preference; does anyone see anything I'm missing? I suppose some people would argue that it's better to have one class per source file, but from my perspective it seems cleaner and more organized to have a non-public top-level class in the same source file.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…