Is there a limit to how deep you can go with inner classes?
Like having a class within a class, within a class, within a class, etc....
I'm just curious.

11 Years
Discussion Span
Last Post by jwenting

there shouldn't be... if each class allowed x inner classes you've still got a potential of infinity levels deep.

it might make your addressing a bit long winded though o_O

weird question!

when classes with inner classes or anonymous classes are compiled they tend to occupy a single addressing level with a hash between the "parent" class and the "child" class. so an object of an inner classtype will be of type:

Package/ParentClass#InnerClass rather than type Package/ParentClass/InnerClass

in theory it should be possible to continue that naming convention indefinately, but in practice, the VM or compiler might not be expecting it.. try it out, let me know =P


I think you'll at some point run into limits for the maximum length of classnames (including package names) which are likely Integer.MAX_VALUE.
Before that you'll possibly run into the maximum size of codefiles (though those can be quite large).

The most serious problem of all of course is that it's horrendously bad design to need anything like that ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.