Is there a way to get a reference to an object that called a method without passing the object to the method arguments? Thanks for reading.
Way to get reference to object that called method?
Collapse
X
-
Tags: None
-
Could you give more details of what you are trying to do? Static method or instance method?
This could be interpreted as
[CODE=java]class {
void aMethod () {
//the this object called this method.
}
}[/CODE] for instance methods but perhaps that's not what you are looking for. -
You can't. The only thing you can do is create a Throwable, make it fill in itsOriginally posted by orangemonkeyIs there a way to get a reference to an object that called a method without passing the object to the method arguments? Thanks for reading.
stack trace and obtain the stack trace. Given the several elements you can obtain
the class name, method name and line number of the callers.
kind regards,
JosComment
-
Cheating !Originally posted by JosAHYou can't. The only thing you can do is create a Throwable, make it fill in its
stack trace and obtain the stack trace. Given the several elements you can obtain
the class name, method name and line number of the callers.
kind regards,
JosComment
-
Thanks for your replies guys! :) I was just wondering if it was possible, because it would be a easier way to solve my problem. I should have realized earlier though that something like that doesn't exist. I'm currently working on the other possible solution to the problem, and if i get stuck, I know where to ask if I need help again :).Comment
-
You never explained your problem. If you did, a forum member may be able to suggest something better -- at least something that isn't a hack!Originally posted by orangemonkeyThanks for your replies guys! :) I was just wondering if it was possible, because it would be a easier way to solve my problem. I should have realized earlier though that something like that doesn't exist. I'm currently working on the other possible solution to the problem, and if i get stuck, I know where to ask if I need help again :).Comment
Comment