Skip to content

Instantly share code, notes, and snippets.

@nkonev
Created October 22, 2013 15:11
Show Gist options
  • Select an option

  • Save nkonev/7102445 to your computer and use it in GitHub Desktop.

Select an option

Save nkonev/7102445 to your computer and use it in GitHub Desktop.
import java.lang.reflect.Method;
// http://www.quizful.net/post/java-reflection-api
public class ReflectionMath{
public static double reflectCall(String func, Object... args) throws Exception{
Method[] methods = Math.class.getMethods();
for(Method method: methods){
String name = method.getName();
if(name.equals(func)){
Double d = (Double) method.invoke(Math.class, args);
return d;
}
}
throw new Exception("Not found Math."+func);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment