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();
1.4m articles
1.4m replys
5 comments
57.0k users