• Post Reply Bookmark Topic Watch Topic
  • New Topic

cyclic inheritance - I dont get it!  RSS feed

 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an interface that I was unsing with several other objects, then dumped all of them except one in the new version of the prog so I figured Hey, lets just throw the interface into the class, nesting it as an "inner interface" so to speak..... Got one of those javac erros that makes you go HUH? cyclic inheritance OK IM lost, I read some on several sites that said it can be done by nestin gthe interface & then implementing it using the fully quantified name like such:
public class PackageData implements PackageData.PositionConstants{
protected String [] packageData(String data) {
String [] inData = new String[91];
}
public interface PositionConstants{
/*Beginning Postitons for extracting data from comma deliminated file */
public static final int [] POSITIONS = {82, 100, 137, 153, 163, 182, 185, 191, 194, 205, 208, 210, 257, 333, 336, 412, 415, 491, 494, 570, 573, 649, 652, 728, 731, 807, 810, 830, 833, 843, 846, 855, 858, 860, 863, 883, 886, 888, 891, 893, 896, 898, 901, 903, 906, 908, 911, 913, 916, 918, 959, 971, 974, 988, 991, 1026, 1029, 1032, 1035, 1038, 1041, 1045, 1048, 1058, 1127, 1142, 1145, 1147, 1150, 1155, 1165, 1171, 1699, 1702, 1752, 1782, 1816, 1846, 1880, 1910, 1944, 1969, 1972, 1977, 1980, 2004, 2029, 2054, 2057, 2062, 2065, 2089, 2114, 2139, 2142, 2147, 2150, 2174, 2199, 2220, 2223, 2228, 2231, 2263, 2283, 2304, 2307, 2312, 2315, 2347, 2367, 2388, 2391, 2396, 2399, 2431, 2451, 2472, 2475, 2480, 2483, 2515, 2535, 2556, 2559, 2564, 2567, 2599, 2619, 2636, 2639, 2644, 2647, 2664, 2667, 2677, 2680, 2689, 2692, 2701, 2704, 2706, 2709, 2726, 2729, 2734, 2737, 2754, 2757, 2767, 2770, 2779, 2782, 2791, 2794, 2796, 2799, 2816, 2819, 2824, 2827, 2844, 2847, 2857, 2860, 2869, 2872, 2881, 2884, 2886, 2889, 2906, 2909, 2914, 2917, 2934, 2937, 2947, 2950, 2959, 2962, 2971, 2974, 2976, 2979, 2996, 2999, 3004, 3007, 3024, 3027, 3037, 3040, 3049, 3052, 3061, 3064, 3066};
}
};
Sorry so long but its the actual code.....NOW, can someone explain to me why this is illegal?
I can get rid of the error by NOT nesting the interface but now my curiousity is peaked & want to know..thanks all
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that should work. Take a look at this article. Maybe Jim can come along and explain it.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Mike thats the article I read....Im stumped too.....makes perfect sense to me, in my demented little mind, but 1.4.1_01 says NO WAY PARTNER!
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of nesting an interface inside a class (inasmuch that there is a purpose; I've never found a need for it) is organizational. You want the interface to always be qualified with the name of the class. Maybe you have a LinkedList class, and you want the node to implement a Node interface. You nest it for clarity, so users have to implement LinkedList.Node. However, your attempt to have the enclosing class implement the interface is giving the compiler a conniption fit. It can't know what the interface is until it compiles the class, but it can't compile the class because it doesn't understand the interface. I imagine the compiler could be implemented in such a way to make sense of this situation anyway. Maybe some do and some don't.
In any case, maybe you should just abandon the interface entirely, and just put your constants directly into the class. As an extra warning, anyone who has access to the array can change your "positions". The final keyword prevents a new array from being assigned to the variable, but doesn't prevent the contents of the current array from changing. It's something to think about.
[ April 14, 2003: Message edited by: Greg Charles ]
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the public on that interface was only there to test this thoery I found in the above mentioned article. Like I said Ive dumped the nesting for now, it wasnt THAT big a deal, just when I see a new & strange compiler error I havent seen before I JUST GOTTA KNOW
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this bug report. This is something that was either allowed or ambiguous prior to JSL 2nd edition, but now it's explicitly disallowed by this section: a class cannot directly depend on itself. This allows the compiler writers to impose a certain order on the classes they analyze. I.e. in order to compile class Foo, you must first compile its superclass Bar, and you don't need to worry about what if something in Bar requires to to first compile class Foo, because that simply won't be allowed. They could have created exceptions to this rule for a case like this (implementing your own nested interface), but I guess they wanted to keep things simple, and there really wasn't much need for this exception.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the info Jim.....kind of makes sense but I do agree they could have probably left this one alone.....well now we know! Thanks again all
[ April 14, 2003: Message edited by: DC Dalton ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew Jimbo would come thru.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!