adg
asked on
reference calling object
Is there a (reasonable) way to reference the calling object without explicitly passing "this". Or in other words, does the called object know who called it?
Thanks!
Thanks!
no
ASKER
Thats what I thought.
There should be a way digging in the assembly code.
But, what's the purpose?
;JOOP!
But, what's the purpose?
;JOOP!
Could throw and catch an exception and parse the trace, then use some reflection.
> Could throw and catch an exception and parse the trace
that'd only get you the method, not the object.
that'd only get you the method, not the object.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> but it would be an object of the same class/type.
but very different state.
and how would you create it?
but very different state.
and how would you create it?
ASKER
Wow, I hadn't realized all these nuances. In this case, I'm just interested in identifying the class of the caller. But I know that isn't exactly what I asked (because I didn't know any better).
>> But it could be fun! And also provide lots of entertainment by debugging and maintaining
Hah, just what I need!
I'm going to raise the points and split them. Thanks for all your help!
>> But it could be fun! And also provide lots of entertainment by debugging and maintaining
Hah, just what I need!
I'm going to raise the points and split them. Thanks for all your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the grade!
>> how would you create it?
I would have to be a bit obtuse and say that it depends. could do a classForName or use the class loader (hopefully it is the same) or use findClass(String name), could access a helper class (or a factory) with the string name, which I think would be preferrable. It depends on where the class is and what constructors are available, if it is that person's class or a library, if it allows for construction outside of the package, what parameters if any, and prob other considerations that I did not mention.
>> but very different state.
I know, that is why it is not a very good way of reference, but it may be good just to get the name. Otherwise, if it is just for knoweldge I would say to use a debugger and set a breakpoint at the part in the code that is of interest.
>> how would you create it?
I would have to be a bit obtuse and say that it depends. could do a classForName or use the class loader (hopefully it is the same) or use findClass(String name), could access a helper class (or a factory) with the string name, which I think would be preferrable. It depends on where the class is and what constructors are available, if it is that person's class or a library, if it allows for construction outside of the package, what parameters if any, and prob other considerations that I did not mention.
>> but very different state.
I know, that is why it is not a very good way of reference, but it may be good just to get the name. Otherwise, if it is just for knoweldge I would say to use a debugger and set a breakpoint at the part in the code that is of interest.