printing java object in the method

How to print the object that has called the method in the method itself.

class abc{

public method1()

{

S.o.p("Print the object that has called this method")

?

}

psvm(string a[])

{

abc aa=new abc();

aa.method1();

}

}

Thanks

Sir

[317 byte] By [msirajuda] at [2007-9-29 12:27:25]
# 1
you have to modify the method's signature.public method1( Object obj ){ System.out.println( obj.getClass().getName(); }}Rommie.
Rommiea at 2007-7-15 2:19:33 > top of Java-index,Archived Forums,Java Programming...
# 2
Or make a new exception and parse the stack trace. This has a performance penalty, though.
nascha at 2007-7-15 2:19:33 > top of Java-index,Archived Forums,Java Programming...
# 3
> Or make a new exception and parse the stack trace.> This has a performance penalty, though.That wont get the object that's making the call (the 'this' of the method that's making the call), but only the class and the method
dpza at 2007-7-15 2:19:33 > top of Java-index,Archived Forums,Java Programming...
# 4
Ah... then you will have to pass the object in, though Rommie's code sample will only print the class name. msirajud, if you print out obj.toString() instead, then Rommie's sample may be just what you're after.
nascha at 2007-7-15 2:19:33 > top of Java-index,Archived Forums,Java Programming...