| Summary: | [override method] Wrong visibility on implemented methods from subinterface | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Alexander Karatarakis <alex.karatarakis> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | daniel_megert, deepakazad, lukas.eder, noopur_gupta, Olivier_Thomann |
| Version: | 3.8 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Move to JDT/UI Probably a bug in StubUtility2.createImplementationStub(). *** This bug has been marked as a duplicate of bug 387940 *** |
Build Identifier: Version: Juno Release Build id: 20120510-1218 We have an interface B extending another interface A and also overrides some methods. If a class implements B and we have eclipse automatically add the unimplemented methods (either through hovering on the class name and selecting "add unimplemented methods" or through Source->Override/Implement methods), then: - Methods of interface A correctly get the public visibility - Methods of interface B correctly get the public visibility - Methods of interface B that override methods of interface A do not get the correct visibility. They have no modifier and obviously the we get an error that we cannot reduce visibility like that. Workaround: Manually add the "public" keyword Reproducible: Always Steps to Reproduce: 1) Have two interfaces, one extending another: public interface InterfaceA{ int methodA(); int methodB(); } public interface InterfaceB extends InterfaceA{ @Override int methodB(); int methodC(); } 2) Create a class that implements that interface and have eclipse automatically add method stubs. The result is: public class FooClass implements InterfaceB{ @Override public int methodA() { // TODO Auto-generated method stub return 0; } @Override int methodB() { // TODO Auto-generated method stub return 0; } @Override public int methodC() { // TODO Auto-generated method stub return 0; } } Since methodB() does not have the "public" modifier, we get an error. PS: You may want to override a method of a super-interface to return a more specific Object type for example. I am aware that in the supplied example we could simply avoid overriding methodB().