Example: If I have two classes: A and B. both class can call a method in C (example: the init() method)
From C, how do we know where the call is from (from Class A or Class B) ?
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.
To do it right, you should provide C’s method with that information, for example via an enum or class parameter:
or
But if you don’t care, there is another way using the stack trace. Have a look at Get current stack trace in Java and use the second StackTraceElement from the top of the stack to get the method that called the current one.