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
> 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?
> > 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.