This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCircularityError  RSS feed

 
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
Sheriff
Posts: 16028
87
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!