View Full Version : Java Inner Class Source Code Separation?

09-29-2007, 05:26 AM
Is is possible to define an inner class within a seperate source file from the outer class? If so, what is the syntax for it?

09-29-2007, 10:18 AM
I don't think so. Inner classes are a property of their outer class, and they're treated the same as any other property. C# has a method for splitting a single class across multiple files, but insofar as I know, Java doesn't. I would suggest, however, that if you need to do so, said class is too big. Break it up more. Inner classes are meant for convenience purposes only. If you end up with a large inner class, consider making it a normal class.

You can always have:
// OuterClass.java

class OuterClass {
public static void main(String[] args) {

InnerClass ic = new InnerClass();
// InnerClass.java

class OuterClass$InnerClass {
public void hello() {
}... and cat them together.