Call Java functions dynamically based on strings
I am building a java unit converter for an android application. I am
offering the user a lot of different unit conversions, it ends up being
220 total conversions possible, 110 if you only count going in one
direction. I.E. meters -> feet and feet -> meters would be two different
conversions.
As of right now, I am planning on writing small methods for each
conversion, so 220 in total ( I think this is probably the easiest way to
go about it, even thought it will take some time). Now my question is,
once I set 2 variables (convertFrom and convertTo) I want to know if it is
possible to call the proper method dynamically? I could just create
if/else if blocks, but that would just end up being an insane amount of
code, and was hoping there was a better way to go about calling the
correct method based off the 2 variables mentioned above. Any advice?
P.S. Sorry about no code here, I am only just getting started here and am
just in the planning phase for this one.
No comments:
Post a Comment