Say I have Method1(void), Method2(void)...
Is there a way i can chose one of those with a variable?
String MyVar=2; MethodMyVar();
Use reflection:
Method method = WhateverYourClassIs.class.getDeclaredMethod("Method" + MyVar); method.invoke();
2.1m questions
2.1m answers
60 comments
57.0k users