Community
Participate
Working Groups
Hello, I have a problem with jdt compiler (same behavior is for sun jdk 1.3.1 and jdk 1.4.1). Refactor -> rename don't work with jdk 1.4.1 (compliance 1.4 in eclipse jdt) and I think that problem is different behavior for protected method in different package. example : package eclipse.a (two classes) package eclipse.a; public class Parent { public Parent() {} protected void doSmth(Object obj) { System.err.println("Parent.doSmth(Object '" + obj + "')"); } protected void doSmth(String str) { System.err.println("Parent.doSmth(String '" + str + "')"); doSmth((Object)str); } } package eclipse.a; import eclipse.b.DerivedB; public class DerivedA extends Parent { private final DerivedB derivedB; public DerivedA(DerivedB derivedB) { super(); this.derivedB = derivedB; } protected void doSmth(String str) { System.err.println("DerivedA.doSmth(String '" + str + "')"); derivedB.doSmth((String)str); } public static void main(String[] args) { DerivedB b = new DerivedB(); DerivedA a = new DerivedA(b); a.doSmth("TEST"); } } Package eclipse.b (one class) package eclipse.b; import eclipse.a.Parent; public class DerivedB extends Parent { public DerivedB() { super(); } protected void doSmth(String str) { System.err.println("DerivedB.doSmth(String '" + str + "')"); } } If compile with jdt 1.3 compliance (and jdk 1.3.1) then result is : java eclipse.a.DerivedA DerivedA.doSmth(String 'TEST') DerivedB.doSmth(String 'TEST') with jdt 1.4 compliance and jdk 1.4.1 result is : java eclipse.a.DerivedA DerivedA.doSmth(String 'TEST') Parent.doSmth(Object 'TEST') Solution for problem is for class DerivedA : package eclipse.a; import eclipse.b.DerivedB; public class DerivedA extends Parent { private final DerivedB derivedB; public DerivedA(DerivedB derivedB) { super(); this.derivedB = derivedB; } protected void doSmth(String str) { System.err.println("DerivedA.doSmth(String '" + str + "')"); ((Parent)derivedB).doSmth((String)str); } public static void main(String[] args) { DerivedB b = new DerivedB(); DerivedA a = new DerivedA(b); a.doSmth("TEST"); } } regards Haris Peco
DerivedB.doSmth(String) isn't visible to DerivedA since it lives in a different package, and isn't inside DerivedA hierarchy. This is the spec'ed behavior.
Closing as invalid.