【发布时间】:2021-04-24 04:48:54
【问题描述】:
我想知道哪个类调用了特定函数。我一直在为此查看文档,但没有成功。我已经知道如何get the name of a class,但这与我正在寻找的不同。我已经找到了something related for java,但对于飞镖我还没有。也许我错过了什么。
假设我有一个这样的打印功能:
class A {
void printSomethingAndTellWhereYouDidIt() {
// Here I would also include the class where this function is
// being called. For instance:
print('you called the function at: ...');
//This dot-dot-dot is where maybe should go what I'm looking for.
}
}
class B {
A a = A();
void test() {
a.printSomethingAndTellWhereYouDidIt();
}
}
输出应该是这样的:
you called the function at: B
如果有办法实现这一点,请告诉我。背后的想法是然后将其与记录器一起使用,例如the logging package。提前谢谢你。
【问题讨论】: