Building a summary for the method signature. - Java Reflection

Java examples for Reflection:Method

Description

Building a summary for the method signature.

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    /**//  w  w w .  j a v a 2  s. c om
     * Building a summary for the method signature.
     *
     * @param   method
     *
     * @return
     */
    public static String buildIdentifier(final Method method) {
        StringBuilder sb = new StringBuilder();

        sb.append(method.getReturnType().getSimpleName());
        sb.append(" ");
        sb.append(method.getName());
        sb.append("(");

        boolean first = true;
        for (Class parameter : method.getParameterTypes()) {
            if (!first) {
                sb.append(", ");
            }

            first = false;
            sb.append(parameter.getSimpleName());
        }

        sb.append(")");

        return sb.toString();
    }
}

Related Tutorials