Hey I'm trying to set a Strategy in my program that should allow me to do something I've never tried before and have no idea if it's either the best approach to the problem or if it is possible or not.


I have a class with some fields and one of them is a String function and I want to check the value of that function (in this case will just be the name of the function) and then find a method with the same name in my class.

How can I do that?

Recommended Answers

All 3 Replies

You can't do it directly, and it's hard to understand why you would want to so--because if you could, the behavior of your program would depend on the names you choose for its components.

How could I do it indirectly?
I just want to know how to verify all the methods used in my class and see if one of them matches with the function I have.

I apreciate all the hints to set the best strategy to this.

You might use a map, with the strings you care about as keys and pointers to the relevant functions as values.

Either that or use an enum type as the value, with one member for each function you care about.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.