Render the class names of the given parameter Types as a comma-delimited String. - Java Reflection

Java examples for Reflection:Class

Description

Render the class names of the given parameter Types as a comma-delimited String.

Demo Code

/**//ww w  . j ava 2s  .c om
 * Copyright (c) 2011 eXtensible Catalog Organization
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the MIT/X11 license. The text of the license can be
 * found at http://www.opensource.org/licenses/mit-license.php.
 */
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;

public class Main{
    /**
     * Render the class names of the given parameterTypes as a comma-delimited String.
     * @param parameterTypes
     * @return
     */
    public static String parameterTypesToString(Class... parameterTypes) {

        String result;
        if (parameterTypes != null && parameterTypes.length > 0) {

            StringBuffer sb = new StringBuffer();
            for (Class c : parameterTypes) {

                sb.append(c.getName()).append(',');

            }

            // Remove trailing comma
            result = sb.toString().substring(0, sb.length() - 1);

        } else {

            result = "null";
        }

        return result;

    }
}

Related Tutorials