check if class has Declared Method - Android java.lang.reflect

Android examples for java.lang.reflect:Method

Description

check if class has Declared Method

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

import android.util.Log;

public class Main {
    public static final String TAG = "ReflectionHelper";

    public static boolean hasDeclaredMethod(Class<?> c, String methodName) {
        try {//ww  w .  j  a  va  2  s .  c om
            for (Method m : c.getDeclaredMethods())
                if (m.getName().equals(methodName))
                    return true;
        } catch (Exception ex) {
            Log.e(TAG, ex.toString());
        }

        return false;
    }
}

Related Tutorials