Here you can find the source of getClassNameAsSrc(Class> clazz)
Parameter | Description |
---|---|
clazz | a parameter |
public static String getClassNameAsSrc(Class<?> clazz)
//package com.java2s; import java.util.Iterator; public class Main { /**/* ww w . j a v a 2s.co m*/ * Gets the name of the given class as it would be declared in Java source code. * * @param clazz * @return */ public static String getClassNameAsSrc(Class<?> clazz) { return getClassNameAsSrc(clazz, 0); } private static String getClassNameAsSrc(Class<?> clazz, int numArrayDimensions) { if (clazz.isArray()) { return getClassNameAsSrc(clazz.getComponentType(), numArrayDimensions + 1); } else { if (numArrayDimensions == 0) { return clazz.getName().replace('$', '.'); } else { StringBuilder classJavaSrcName = new StringBuilder(clazz.getName().replace('$', '.')); for (int n = 0; n < numArrayDimensions; n++) { classJavaSrcName.append("[]"); } return classJavaSrcName.toString(); } } } public static String toString(Iterable<String> strs) { StringBuilder ret = new StringBuilder(); for (Iterator<String> i = strs.iterator(); i.hasNext();) { ret.append(i.next()); if (i.hasNext()) ret.append(","); } return ret.toString(); } }