public static String className(Class<?> clazz) { //todo: rename
        //todo: is that correct algorithm?
        final String naiveName = clazz.getName();
        if (!clazz.isArray()) { //todo: what about enum
            return naiveName;
        } else {
            int count = 0;
            String ending = "";
            while (clazz.isArray()) {
                count++;
                ending += "[]";
                clazz = clazz.getComponentType();
            }
            if (clazz.isPrimitive()) {
                String primitiveClassName;
                if (clazz == boolean.class) {
                    primitiveClassName = "boolean";
                } else if (clazz == byte.class) {
                    primitiveClassName = "byte";
                } else if (clazz == char.class) {
                    primitiveClassName = "char";
                } else if (clazz == short.class) {
                    primitiveClassName = "short";
                } else if (clazz == int.class) {
                    primitiveClassName = "int";
                } else if (clazz == long.class) {
                    primitiveClassName = "long";
                } else if (clazz == float.class) {
                    primitiveClassName = "float";
                } else if (clazz == double.class) {
                    primitiveClassName = "double";
                } else {
                    throw new RuntimeException("Never here! - You try to generate code for Void[]...[]: clazz = " + clazz);
                }
                return primitiveClassName + ending;
            } else {
                return naiveName.substring(count + 1, naiveName.length() - 1) + ending;
            }
        }
    }
public static String className(Class<?> clazz) { 
        
        final String naiveName = clazz.getName();
        if (!clazz.isArray()) { 
            return naiveName;
        } else {
            int count = 0;
            String ending = "";
            while (clazz.isArray()) {
                count++;
                ending += "[]";
                clazz = clazz.getComponentType();
            }
            if (clazz.isPrimitive()) {
                String primitiveClassName;
                if (clazz == boolean.class) {
                    primitiveClassName = "boolean";
                } else if (clazz == byte.class) {
                    primitiveClassName = "byte";
                } else if (clazz == char.class) {
                    primitiveClassName = "char";
                } else if (clazz == short.class) {
                    primitiveClassName = "short";
                } else if (clazz == int.class) {
                    primitiveClassName = "int";
                } else if (clazz == long.class) {
                    primitiveClassName = "long";
                } else if (clazz == float.class) {
                    primitiveClassName = "float";
                } else if (clazz == double.class) {
                    primitiveClassName = "double";
                } else {
                    throw new RuntimeException("Never here! - You try to generate code for Void[]...[]: clazz = " + clazz);
                }
                return primitiveClassName + ending;
            } else {
                return naiveName.substring(count + 1, naiveName.length() - 1) + ending;
            }
        }
    }
public static String className ( Class < ? > clazz ) { //todo: rename //todo: is that correct algorithm? final String naiveName = clazz . getName ( ) ; if ( ! clazz . isArray ( ) ) { //todo: what about enum return naiveName ; } else { int count = 0 ; String ending = "" ; while ( clazz . isArray ( ) ) { count ++ ; ending += "[]" ; clazz = clazz . getComponentType ( ) ; } if ( clazz . isPrimitive ( ) ) { String primitiveClassName ; if ( clazz == boolean . class ) { primitiveClassName = "boolean" ; } else if ( clazz == byte . class ) { primitiveClassName = "byte" ; } else if ( clazz == char . class ) { primitiveClassName = "char" ; } else if ( clazz == short . class ) { primitiveClassName = "short" ; } else if ( clazz == int . class ) { primitiveClassName = "int" ; } else if ( clazz == long . class ) { primitiveClassName = "long" ; } else if ( clazz == float . class ) { primitiveClassName = "float" ; } else if ( clazz == double . class ) { primitiveClassName = "double" ; } else { throw new RuntimeException ( "Never here! - You try to generate code for Void[]...[]: clazz = " + clazz ) ; } return primitiveClassName + ending ; } else { return naiveName . substring ( count + 1 , naiveName . length ( ) - 1 ) + ending ; } } }
<p> Integer[][].class -> "Integer[][]"
<p> int[][].class -> "int[][]"
<p> Naive: Integer[][].class.getName() -> "[[Ljava.lang.Integer;"
<p> Naive: int[][].class.getName() -> "[[LI;"
<p > Integer [] [] . class - > Integer [] [] <p > int [] [] . class - > int [] [] <p > Naive : Integer [] [] . class . getName () - > [[ Ljava . lang . Integer ; <p > Naive : int [] [] . class . getName () - > [[ LI ;