0

I would like to access a protected method from a variable. For example,

A.java (a third-party library, like Spring's class)

package a;
public class A {
    protected void doA() {}
}

B.java (my own class)

package b;

public class B {
    public void doB(A a) {
       // how to invoke a.doA() here.
    }
}

As you can see from above, is there a way to access a.doA() in my own class withour using reflection?

Derek Yang
  • 33
  • 4
  • The "without reflection" part of the question shows you already knew the answer. This might be an XY problem. Can you give us some idea of your broader objective? http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Paul Boddington Nov 25 '15 at 03:36
  • if a.A is a thrid-party library, and I want to invoke it by the class in b.B (my own class), how can I do ? – Derek Yang Nov 25 '15 at 03:38
  • I don't think so, you can create a C.java which is under `a` package. And then it's possible to invoke A.doA() there. For example, ` package a; public class C { public static void doA(A a) { a.doA(); } } ` and then you can use C.doA(a); to invoke it in your own class (b.B) – jumperchen Nov 25 '15 at 03:46

0 Answers0