Nested/Inner class in external file
Objects of inner classes keep implicit references to the objects of the paren class.
If the nested class is not static
(it is inner) you can not. But if the nested class does not need access to the parent's class instances directly and does not need access to the private fields, than should be ok to refactor, move the inner class out and do not declare it public (out of that package can not be accessed).
No. Java source codes can not be split across multiple files. You'd need a construct similar to a partial class as in C#, which Java does not have.
i think you have a god object or something like that, think in refactor your code
http://en.wikipedia.org/wiki/God_object
You can make the inner class package private which means that it will only be accessible from other classes in exactly the same package. This is also done quite frequently for hidden classes inside the standard JDK packages like java.lang
or java.util
.
in pkg/MyClass.java
public class MyClass {
...
}
in pkg/MyHiddenClass.java
class MyHiddenClass {
final MyClass outer;
MyHiddenClass( MyClass outer )
{
this.outer = outer;
}
...
}
Now when you want to access methods or variables of the outer class you need to prefix them with outer.
but you get essentially the same functionality as before when the reference to the outer instance was synthetically created by the compiler.