Android examples for java.lang.reflect:Method Invoke
safe Call Method
//package com.java2s; import java.lang.reflect.Method; public class Main { @SuppressWarnings("unchecked") public static <T> T safeCallMethod(Object object, Method method, T defaultResult, Object... args) { try {/*from w ww. ja v a2 s . co m*/ return (T) method.invoke(object, args); } catch (Exception ex) { return defaultResult; } } }