Article View: borland.public.jbuilder.java.language
Article #18682Re: How to know the caller of a method?
From: Regis Eloi
Date: Sun, 17 May 1998 00:00
Date: Sun, 17 May 1998 00:00
42 lines
1907 bytes
1907 bytes
soklay wrote:
> Hi all,
>
> Anyone knows whether there any way to know who is/are the
> caller(s) of a method during run-time? In a method, I would
> like to get hold of the string name of the class and method
> which calls it. Else, is it possible to, in a method, get hold
> if the name of itself and the name of the class it is declared
> in at run-rime?
>
> Any help very much appreciated.
I don't really understand what you're trying to do, but if the following
can help you...You can't know the caller, except if you pass it as a
parameter.
Class A {
B b = B();
b.myMethod(...,this);
}
Class B {
void my Method(...,Object o) {
//now we've got the caller, we can get the class and therfore the name
of the class
Class c = o.getClass();
String s = c.getName(); // s = "A"
}
Get the name of the method is a little bit more complex. Try to read
about the class java.lang.Class.
Hope that helps.
Regis
--
________________________________________________________________________
Regis Eloi mailto:R.Eloi@dcs.hull.ac.uk
The University of Hull (England) - Department of Computer Science
Institut d'Informatique d'Entreprise (France)
My CV is on the Web at http://www-eleves.iie.cnam.fr/eloi/cv_en.html
________________________________________________________________________
Technical Details
Message-ID:
<355EDA37.F89840E2@dcs.hull.ac.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6jirgc$haf4@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,81abe3417e28e50d X-Google-Attributes: gidf74b3,public From: Regis Eloi <R.Eloi@dcs.hull.ac.uk> Subject: Re: How to know the caller of a method? Date: 1998/05/17 Message-ID: <355EDA37.F89840E2@dcs.hull.ac.uk> X-Deja-AN: 354012467 Content-Transfer-Encoding: 7bit References: <6jirgc$haf4@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: University of Hull Mime-Version: 1.0 Reply-To: R.Eloi@dcs.hull.ac.uk Newsgroups: borland.public.jbuilder.java.language