Retrieve the caller instance (not class) of a method or constructor

后端 未结 1 1073
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 13:16

Is it possible to retrieve the caller instance of a method/constructor?

This question has already been posted, but each time the answers are talking about caller Cla

相关标签:
1条回答
  • 2021-01-18 13:54

    Your gut feeling is right - it's not possible. Personally I think that's a good thing, as it would make code pretty fragile with respect to refactoring (imagine pulling some code out into a static method - suddenly there's no caller object at all).

    If you want to express some sort of owner relationship, you should provide that owner explicitly.

    0 讨论(0)
提交回复
热议问题