get Method Signature - Java Reflection

Java examples for Reflection:Method Parameter

Description

get Method Signature

Demo Code

/**//www . j  a  va2 s .c o m
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */
//package com.java2s;

public class Main {


    public static final String CLINIT = "<clinit>";
    public static final String INIT = "<init>";

    public static String getMethodSignature(String name,
            Class... parameterTypes) {
        StringBuilder builder = new StringBuilder();
        builder.append(name);
        if (!(name.equals(CLINIT) || name.equals(INIT))) {
            builder.append("(");
            if (parameterTypes != null) {
                for (int i = 0; i < parameterTypes.length; i++) {
                    if (i > 0) {
                        builder.append(", ");
                    }
                    builder.append(parameterTypes[i].getName());
                }
            }
            builder.append(")");
        }
        return builder.toString();
    }
}

Related Tutorials