Re: Getting class name without instance?

From: Chris (chris2k01_at_hotmail.com)
Date: 11/29/03


Date: Sat, 29 Nov 2003 07:49:25 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sibyl wrote:

[snip]
> import org.apache.log4j.Logger;
>
> public class Foo {
> ...
>
> private static Logger logger = Logger.getLogger([get either Class
> object or class name here--the result should be the Class Foo.class
> or its fully qualified name as a String]);
> }
>
> ------------
> The point is that this same statement needs to be in every class
> where logging is done, and I would like them all to be identical.
[snip]

Hi,
How about:

java.lang.Class c = Foo.class;

and do whatever you need with the Class object, like getName().

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/x98JwxczzJRavJYRAqkOAJ9Lv9qhdkR5ZuSMbDamBcvgLjqIpwCgwsRn
0A0fipDLig1JjhktjKWsReE=
=zLFy
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: syntax for fixed array in C#?
    ... Look at other Encoding.* classes ... Austin ...
    (microsoft.public.dotnet.general)
  • Re: Getting class name without instance?
    ... > Hash: SHA1 ... > Sibyl wrote: ... >> public class Foo { ... >> The point is that this same statement needs to be in every class where ...
    (comp.lang.java)
  • Re: Win32::OLE problem
    ... The statement needs to be in the form: ... I'm trying to write a little perl script to enter contacts into a Lotus ...
    (comp.lang.perl.misc)