safe Call Method - Android java.lang.reflect

Android examples for java.lang.reflect:Method Invoke

Description

safe Call Method

Demo Code


//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;
        }
    }
}

Related Tutorials