I’ve 3 methods A(), B() and C(), both A() and B() call C(). In method C(), how can I know it call from A() or B()?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t recommend this approach – other posters point out better ways of handling this. But if you really, really need to know who called you, without changing
C()‘s parameters, you can do this:Note that generating a StackTrace is somewhat costly. Not a big deal, though, unless you’re doing it in code that you’re calling very frequently.
Again, you almost certainly find a better way of doing whatever you’re trying to do.