The java compiler is not going to enter an infinite loop when trying to introduce a loop chain of inheritance. In the end, each inheritance chain is a finite finite graph (and, with computational account, with a very small number of nodes and edges). More precisely, the inheritance graph from subclass A to the (possible) superclass Z should be a string (and not a different path, though), and the compiler can easily determine whether it is a string or not.
It does not take a long time for the program to determine if such a small graph is cyclic or not, or if it is a string or not, which the compiler does. Thus, the compiler does not go into an infinite loop, and the JVM never ends from the stack space, since 1) no compiler works on the JVM, nor 2) the JVM does not start (because it does not compile, and the compiler never calls under such conditions JVM anyway.)
I don’t know any language that allows such cyclical inheritance graphs (but I have not done anything except Java for 11 years, so my memory of anything other than Java is soft.) I don’t see, besides, the use of such a design (in modeling or in real life). Perhaps theoretically this is interesting.
change
Ok, I ran your code and really caused a stack overflow. You were right. I need to sit and really study this to understand why the compiler allows such a design.
Nice to find !!!!
luis.espinal
source share