• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCircularityError

 
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();


}
}
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic