简体   繁体   中英

Private method inception in jython

this is my first question in this forum, I've been searching with no luck for my case.

the call hierarchy is as follow:

public class ClassA {
    private methodA() {
            a = methodB()
    return a
    }

    private methodB(){
           b =  methodC()
    return b
    }

    private methodC(){
       c = 5 + 1
    return c
    }
}

all of methods are in the same class

I invoke the private method A using following code in jython:

m = object.class.getDeclaredMethod("methodA")
m.setAccessible(True)
m.invoke(object)

the question is will the the setAccessible modifier propagated to other private method. and all method will be successfully return the expected value?

please help me.

I don't know jython for sure. But it seems that m is identical with your methodA. If you set m (or methodA respectively) to be accessible you will not set methodB accessible.

But as you can now call methodA, this method has no problem calling other private methods from its own class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM