简体   繁体   English

Jython中的私有方法启动

[英]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: 我在jython中使用以下代码调用私有方法A:

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

the question is will the the setAccessible modifier propagated to other private method. 问题是setAccessible修饰符是否会传播到其他私有方法。 and all method will be successfully return the expected value? 并且所有方法都将成功返回期望值?

please help me. 请帮我。

I don't know jython for sure. 我不确定jython。 But it seems that m is identical with your methodA. 但是看来m与您的methodA相同。 If you set m (or methodA respectively) to be accessible you will not set methodB accessible. 如果将m(或分别设置为methodA)设置为可访问,则不会将methodB设置为可访问。

But as you can now call methodA, this method has no problem calling other private methods from its own class. 但是,正如您现在可以调用methodA一样,此方法从其自己的类中调用其他私有方法没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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