Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCircularityError

 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to JLS,
If circularly declared classes are detected at run time, as classes are loaded
(�12.2), then a ClassCircularityError is thrown.
But when I try this program, I get a compiler Error :cyclic inheritance involving A.

class A extends C
{
int x,u;
}
class C extends B
{
int a,b;
}
class B extends A
{
int g,h;
}
public class circulartest
{
public static void main(String[] args) {
A a=new A();


}
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note what it says: "If circularly declared classes are detected at runtime...".

In your case, it is detected at compile time, so you get a compiler error.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is pretty "smart" and I have never seen a case where someone has successfully created a circular reference where it got past the compiler and made it to run-time. The way the compiler handles your classes makes it very easy for it to catch this type of problem before it ever runs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic