Community
Participate
Working Groups
The followed code compiles in Eclipse 3.6 but doesn't with sun javac from JDK 1.6.0_20. javac reports one error: ConcreteClass.java:9: getText() in AClass cannot be applied to(java.lang.String) ---------------------- public class AClass { public String getText() { return ""; } } ---------------------- public class ConcreteClass extends AClass { private static String getText(String arg) { return arg; } static class StaticClass extends ConcreteClass { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } ----------------------
Interesting example. While the nested class doesn't have access to the super class's private method, the super class also happens to be the enclosing class and as such it has access to the enclosing class's private method. Not clear immediately that the bug is with eclipse and not with javac. See that the code compiles alright with javac if you remove the extends clause. I'll follow up.
This looks like a javac bug. Have you reported this to Sun ? The javac compiler seems to exhibit some interesting behavior: case (1) (same case as comment#0, but in one file) -------- public class ConcreteClass extends AClass { private static String getText(String arg) { return arg; } static class StaticClass extends ConcreteClass { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } class AClass { public String getText() { return ""; } } JDK5,6,7 refuse to compile this. case (2) -------- public class ConcreteClass // extends AClass // extends commented out. { private static String getText(String arg) { return arg; } static class StaticClass extends ConcreteClass { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } class AClass { public String getText() { return ""; } } JDK5,6,7 compile this OK. case (3) -------- public class ConcreteClass extends AClass { private static String getText(String arg) { return arg; } static class StaticClass // extends ConcreteClass // extends commented out { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } class AClass { public String getText() { return ""; } } JDK5,6,7, compile this OK. case (4) -------- // AClass is totally out of the picture public class ConcreteClass { private static String getText(String arg) { return arg; } static class StaticClass extends ConcreteClass { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } JDK5,6,7 compile this OK. case (5) -------- // private method changed to public. public class ConcreteClass extends AClass { public String getText(String arg) { // Note private changed to public return arg; } class StaticClass extends ConcreteClass { public String getAbbreviatedText(int endIndex){ return getText("").substring(0, endIndex); } } } class AClass { public String getText() { return ""; } } compiles OK with JDK5,6,7. In summary, the method is accessible and applicable, so I don't see why the code should be rejected at all.
Hi Srikanth, thanks for the evaluation. I've submitted a new bug report (I couldn't find existing one, the search on sun/oracle bug database delivers too much unrelated stuff). As usually, you never receive any immediate feedback, but if I have luck and they will accept the bug, I will post here a link to it. Regards, Andrei
(In reply to comment #3) > Hi Srikanth, thanks for the evaluation. > > I've submitted a new bug report Hi Andrei, Thanks for following this up with Sun/Oracle. Can you share the defect number ? Thanks.
Here is a link (still not accessible): http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6986202
Closing this as INVALID, as this is very likely a javac compiler bug. If Sun/Oracle disagree with justification, please reopen.
Verified for 3.7M3