Example usage for java.lang.reflect Method toString

List of usage examples for java.lang.reflect Method toString

Introduction

In this page you can find the example usage for java.lang.reflect Method toString.

Prototype

public String toString() 

Source Link

Document

Returns a string describing this Method .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Main cls = new Main();
    Class c = cls.getClass();//w  w w. j  av a 2 s.c  o m

    // parameter type is null
    Method m = c.getMethod("show", null);
    System.out.println("method = " + m.toString());

    // method Long
    Class[] cArg = new Class[1];
    cArg[0] = Long.class;
    Method lMethod = c.getMethod("showLong", cArg);
    System.out.println("method = " + lMethod.toString());
}

From source file:Main.java

public static void main(String[] args) {

    Main cls = new Main();
    Class c = cls.getClass();/* ww w  . j a  va  2 s  .c  o m*/

    try {
        Method m = c.getDeclaredMethod("show", null);
        System.out.println("method = " + m.toString());

        // method Integer
        Class[] cArg = new Class[1];
        cArg[0] = Integer.class;
        Method lMethod = c.getDeclaredMethod("showInteger", cArg);
        System.out.println("method = " + lMethod.toString());
    } catch (NoSuchMethodException e) {
        System.out.println(e.toString());
    }
}

From source file:SpecificMethodInfoDemo.java

public static void main(final String[] args) {
    final Method byteValueMeth;
    final Method waitMeth;
    final Method waitDetailMeth;

    try {//  ww w .j  a  v a 2s.co m
        byteValueMeth = Number.class.getMethod("byteValue", null);
        waitMeth = Number.class.getMethod("wait", new Class[] {});
        waitDetailMeth = Number.class.getMethod("wait", new Class[] { long.class, int.class });
    } catch (final NoSuchMethodException ex) {
        throw new RuntimeException(ex);
    }

    System.out.println("byteValueMeth = " + byteValueMeth.toString());
    System.out.println("waitMeth = " + waitMeth.toString());
    System.out.println("waitDetailMeth = " + waitDetailMeth.toString());
}

From source file:SpecificMethodInfoDemo.java

/**
 * Demo method./*from w w w .  j a  va 2  s.c  o  m*/
 * 
 * @param args
 *          Command line arguments.
 * 
 * @throws RuntimeException
 *           If there is a reflection problem.
 */
public static void main(final String[] args) {
    final Method byteValueMeth;
    final Method waitMeth;
    final Method waitDetailMeth;

    try {
        byteValueMeth = Number.class.getMethod("byteValue", null);
        waitMeth = Number.class.getMethod("wait", new Class[] {});
        waitDetailMeth = Number.class.getMethod("wait", new Class[] { long.class, int.class });
    } catch (final NoSuchMethodException ex) {
        throw new RuntimeException(ex);
    }

    System.out.println("byteValueMeth = " + byteValueMeth.toString());
    System.out.println("waitMeth = " + waitMeth.toString());
    System.out.println("waitDetailMeth = " + waitDetailMeth.toString());
}

From source file:Main.java

public static void printMethods(Class cl) {
    Method[] methods = cl.getDeclaredMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];
        System.out.println(m.toString());

    }/*from  www .ja  v a 2  s.  c  o m*/
}

From source file:Main.java

public static void getTelephonyManagerMethods(Context context) {
    String out;/*ww w .  j  a  v a 2s . c o m*/
    try {
        File dir = new File(String.valueOf(context.getFilesDir()));
        // create the file in which we will write the contents
        String fileName = "telephony.txt";
        File file = new File(dir, fileName);
        FileOutputStream os = new FileOutputStream(file);
        Class<?> c = Class.forName(GENERIC);
        Method[] cm = c.getDeclaredMethods();
        for (Method m : cm) {
            out = m.toString() + "\n";
            os.write(out.getBytes());
        }
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.spring4gwt.server.RpcHelper.java

private static String getSourceRepresentation(Method method) {
    return method.toString().replace('$', '.');
}

From source file:ome.util.ReflectionUtils.java

/**
 * call getter and return object.//from   www .j a v a 2  s  .  c  om
 * 
 * @DEV.TODO there maybe be cases where an exception is ok
 * @param target
 *            object on which to call getter
 * @param getter
 *            method for some field
 * @return value stored in field
 */
public static Object invokeGetter(Object target, Method getter) {
    RuntimeException re = new RuntimeException("Error trying to get value: " + getter.toString());
    Object result = null;
    try {
        result = getter.invoke(target, new Object[] {});
    } catch (IllegalArgumentException e) {
        re.initCause(e);
        throw re;
    } catch (IllegalAccessException e) {
        re.initCause(e);
        throw re;
    } catch (InvocationTargetException e) {
        re.initCause(e);
        throw re;
    }
    return result;
}

From source file:ome.util.ReflectionUtils.java

public static void setToNull(Object obj, Method setter) {
    RuntimeException re = new RuntimeException("Error trying to set to null: " + setter.toString());

    try {/*from w  w w . j  a v  a2  s  .  c o  m*/
        setter.invoke(obj, new Object[] { null });
    } catch (IllegalArgumentException e) {
        re.initCause(e);
        throw re;
    } catch (IllegalAccessException e) {
        re.initCause(e);
        throw re;
    } catch (InvocationTargetException e) {
        re.initCause(e);
        throw re;
    }
}

From source file:MethodHashing.java

/**
 * Calculate method hashes. This algo is taken from RMI.
 * /* w w w. ja  va 2s.  co  m*/
 * @param intf
 * @return the map
 */
public static Map getInterfaceHashes(Class intf) {
    // Create method hashes
    Method[] methods = intf.getDeclaredMethods();
    HashMap map = new HashMap();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        try {
            long hash = methodHash(method);
            map.put(method.toString(), new Long(hash));
        } catch (Exception e) {
        }
    }

    return map;
}