Can I get method name dynamically?

I want a class get calling method name dynamically .

e.g. The class is named DynGetMethod,it has a method getMethodName().

If a class Test with a method test1() call it,class DynGetMethod can get method name "test1".

Code maybe like this:

/**Start**/

class Test {

DynGetMethod dyn = new DynGetMethod();

void test1(){

System.out.println(dyn.getMethodName());

}

}

/**End**/

It will print "test1".

How can I implement the method getMethodName()?

Thanks !

[549 byte] By [sunshouhua] at [2007-9-26 23:51:11]
# 1

And more:

If DynGetMethod() defined in a parent class ,then its child class call it ,it should return child method name.

Code like this:

/**start**/

class TestParent(){

DynGetMethod dyn = new DynGetMethod();

String getMethName(){

return dyn.getMethodName();

}

}

class TestChild extends TestParent(){

void test2(){

System.out.println(getMethName());

}

}

/**end**/

It will print "test2",not "getMethName".

Can it do this?

Thanks.

sunshouhua at 2007-7-4 14:06:12 > top of Java-index,Archived Forums,Java Programming...
# 2
i think u referring to this:java.lang.reflect package.u try to take a look i oso not very sure.
Yukiri at 2007-7-4 14:06:12 > top of Java-index,Archived Forums,Java Programming...
# 3
First thanks.Yes I know reflect package.But it can only get class name not calling method name.Maybe I don't know the way.
sunshouhua at 2007-7-4 14:06:12 > top of Java-index,Archived Forums,Java Programming...