Example usage for java.lang Class getMethod

List of usage examples for java.lang Class getMethod

Introduction

In this page you can find the example usage for java.lang Class getMethod.

Prototype

@CallerSensitive
public Method getMethod(String name, Class<?>... parameterTypes)
        throws NoSuchMethodException, SecurityException 

Source Link

Document

Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object.

Usage

From source file:Main.java

public static boolean cancelBondProcess(Class btClass, BluetoothDevice device) throws Exception {
    return ((Boolean) btClass.getMethod("cancelBondProcess", new Class[0]).invoke(device, new Object[0]))
            .booleanValue();//w w  w. j  av  a2 s . co m
}

From source file:Main.java

public static boolean createBond(Class btClass, BluetoothDevice btDevice) throws Exception {
    return ((Boolean) btClass.getMethod("createBond", new Class[0]).invoke(btDevice, new Object[0]))
            .booleanValue();/*  w  w w .j a va 2 s.  c om*/
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static boolean hasMethod(Class clazz, String methodName, Class paramTypes[]) {
    try {/*from  ww w. j  av a2  s .  co m*/
        clazz.getMethod(methodName, paramTypes);
        return true;
    } catch (NoSuchMethodException ex) {
        return false;
    }
}

From source file:Main.java

public static String getProp(String prop) {
    try {//  ww  w .  ja va  2 s . c o  m
        Class<?> c = Class.forName("android.os.SystemProperties");
        Method m = c.getMethod("get", String.class);
        return (String) m.invoke(null, prop);
    } catch (Throwable e) {
        return "";
    }
}

From source file:Main.java

public static boolean cancelBondProcess(Class class1, BluetoothDevice bluetoothdevice) throws Exception {
    return ((Boolean) class1.getMethod("cancelBondProcess", new Class[0]).invoke(bluetoothdevice,
            new Object[0])).booleanValue();
}

From source file:Main.java

public static boolean removeBond(Class class1, BluetoothDevice bluetoothdevice) throws Exception {
    return ((Boolean) class1.getMethod("removeBond", new Class[0]).invoke(bluetoothdevice, new Object[0]))
            .booleanValue();//w  ww .  j a v  a  2 s  .c o  m
}

From source file:Main.java

public static boolean cancelPairingUserInput(Class class1, BluetoothDevice bluetoothdevice) throws Exception {
    return ((Boolean) class1.getMethod("cancelPairingUserInput", new Class[0]).invoke(bluetoothdevice,
            new Object[0])).booleanValue();
}

From source file:Main.java

/**
 * @param cls/* w ww.  j a  v a2  s .co  m*/
 * @param argClass
 * @return Method of fromValue with argClass
 */
private static Method fromValueMethod(Class cls, Class argClass) {
    try {
        return cls.getMethod("fromValue", new Class[] { argClass });
    } catch (Throwable t) {
        return null;
    }
}

From source file:Main.java

public static Type getMethodType(Class<?> paramClass, String paramString) {
    try {//from   w w w.j  av  a 2s  .c  om
        Type localType = paramClass.getMethod(paramString, new Class[0]).getGenericReturnType();
        return localType;
    } catch (Exception localException) {
    }
    return null;
}

From source file:Main.java

public static Object invokeObjectMethod(Object object, String methodName, Class[] argsClass, Object[] args) {
    Object returnValue = null;/*from w w  w. java2s .  co  m*/
    try {
        Class<?> c = object.getClass();
        Method method;
        method = c.getMethod(methodName, argsClass);
        returnValue = method.invoke(object, args);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnValue;
}