What is the Maximum Type Depth?

I saw this question posted as an answer, but no one seems to have asked it since.

What is the maximum number of levels classes can inherit?

In other words, what are the maximum N and M such that the following will still compile?

public virtual class C1 { }
public virtual class C2 extends C1 { }
// ...
public virtual class CN extends CM { }

Answer

The Maximum Type Depth appears to be 10. That means the maximum N is 11 and the maximum M is 10. Attempts to compile the following class will illustrate:

virtual class C1 {}
virtual class C2 extends C1 {}
virtual class C3 extends C2 {}
virtual class C4 extends C3 {}
virtual class C5 extends C4 {}
virtual class C6 extends C5 {}
virtual class C7 extends C6 {}
virtual class C8 extends C7 {}
virtual class C9 extends C8 {}
virtual class C10 extends C9 {}
virtual class C11 extends C10 {}
virtual class C12 extends C11 {}

The above will throw the following compile error:

Line: 12, Column: 7
C12: Maximum type depth exceeded: 10

Attribution
Source : Link , Question Author : Adrian Larson , Answer Author : Adrian Larson

Leave a Comment