My principal problem is how to find out whitch object type called specific method.
Is out there any solution that do no use stack trace ?
If not why such information are not avaiable ? it could be very helpfull.
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.
Basically, no. Certainly, there is no good solution that doesn’t use exception objects and stack traces under the hood. (However, you don’t need to parse the stack trace text. You can get hold of the array of StackFrame objects that contain the same information.)
In theory, you could avoid using the stacktrace mechanisms by passing an extra parameter to say who the caller is. However this is complicated and really messes up your code if you do it by hand, and problematic if you try to do it automatically.
Because:
making the information available cheaply is going to cause ordinary method calls to be more expensive due to necessary changes to the method call/return “protocol”,
in general, it is a bad idea for the behavior of a method to depend on what method called it, and
the stack trace mechanism does the job anyway, especially if you are only capturing the calling method for diagnostic / tracing purposes.