get Method Argument Names String - Java Reflection

Java examples for Reflection:Method Name

Description

get Method Argument Names String

Demo Code


//package com.java2s;
import java.lang.reflect.Method;

public class Main {

    public static String getArgumentNamesStr(Method method) {
        StringBuilder sb = new StringBuilder();
        Class<?>[] parameters = method.getParameterTypes();
        for (int i = 0; i < parameters.length; i++) {
            sb.append(parameters[i].getName());
            if (i != parameters.length - 1) {
                sb.append(",");
            }//from  w w w.j  a  v  a2 s.c o m
        }

        return sb.toString();
    }

    public static String getArgumentNamesStr(Class<?>[] parameters) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < parameters.length; i++) {
            sb.append(parameters[i].getName());
            if (i != parameters.length - 1) {
                sb.append(",");
            }
        }

        return sb.toString();
    }
}

Related Tutorials