execute method by the string name

Well,

I want execute a method , just knowing the string name of her and your class too:

public class A

{

public static void Kick()

{

}

}

public class B

{

final String methodToBeExecuted="Kick";

}

Or on the same class too.

This is possible?

(In C I could use functions pointers on an array)

A solution can use @Anotation ou "Reflection"

Thanks

[445 byte] By [dreampeppers99a] at [2007-11-27 10:56:43]
# 1

From todays threads:

http://forum.java.sun.com/thread.jspa?threadID=5196077

CeciNEstPasUnProgrammeura at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...
# 2

i've never seen anything like that, my advice is to look closer at your design because your problem is very easy to circumvent

JFrustrationa at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...
# 3

CeciNEstPasUnProgrammeur this thread dont help, but thanks.

dreampeppers99a at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...
# 4

> i've never seen anything like that, my advice is to

> look closer at your design because your problem is

> very easy to circumvent

Ok but this is not a desing problem.

It's just a performatic problem.

Im coding an emulator and need to handle opcode.

swicth (opcode)

{

case 0x1:

method1();

case 0xA:

methodA();

This code (one processor that have 256 instructions) can produce a slow program and change it to a thing like this:

final String instruction = "method" + opcode;

Is very very very fast... and build an emulator we nedd to forget a little about the patterns and good pratices and make performatic things.

understood?

dreampeppers99a at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...
# 5

> understood?

No.

And I also don't see why the thread I linked doesn't give you information about how to invoke a method by name. I did say you should look at Class and Reflection.

CeciNEstPasUnProgrammeura at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...
# 6

> > understood?

>

> No.

>

> And I also don't see why the thread I linked doesn't

> give you information about how to invoke a method by

> name. I did say you should look at Class and

> Reflection.

Ok Ill try thanks.

dreampeppers99a at 2007-7-29 12:04:39 > top of Java-index,Java Essentials,Java Programming...