Java:如何识别类是否调用特定方法

时间:2019-02-11 23:13:08

标签: java reflection

是否有可能使用反射来识别特定Java类中的某个方法在构建时是否调用了另一个方法?

假设我有

  • 声明methodA1()的ClassA
  • 声明methodB1(),methodB2(),methodB3()的ClassB

我想在构建时知道ClassB的任何成员是否调用methodA1()。有可能吗?

我现在正在使用JDK8。

我很惊讶我找不到这个问题,这让我觉得这很幼稚。

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以使用

class AdminProductsController extends AdminProductsControllerCore {
    protected function copyFromPost(&$object, $table) {
        if ( $this->isTabSubmitted( 'Informations' ) ) {
            if ( $this->checkMultishopBox( 'is_exclusive', $this->context ) ) {
                $object->is_exclusive = (int) Tools::getValue( 'is_exclusive' );
            }

        }
    }
}

也许这不是最好的方法,因为您必须深入研究返回的Thread.currentThread().getStackTrace() 数组。