ClassTypeUtils { public static String getTypeStr(Class clazz) { String typeStr = ReflectCache.getTypeStrCache(clazz); if (typeStr == null) { if (clazz.isArray()) { String name = clazz.getName(); typeStr = jvmNameToCanonicalName(name); } else { typeStr = clazz.getName(); } ReflectCache.putTypeStrCache(clazz, typeStr); } return typeStr; }  static Class[] getClasses(String[] typeStrs); static Class getClass(String typeStr); static String canonicalNameToJvmName(String canonicalName); static String[] getTypeStrs(Class[] types); static String[] getTypeStrs(Class[] types, boolean javaStyle); static String getTypeStr(Class clazz); static String jvmNameToCanonicalName(String jvmName);  }
@Test public void testGetTypeStr() { Assert.assertEquals(ClassTypeUtils.getTypeStr(String.class), "java.lang.String"); Assert.assertEquals(ClassTypeUtils.getTypeStr(boolean.class), "boolean"); Assert.assertEquals(ClassTypeUtils.getTypeStr(byte.class), "byte"); Assert.assertEquals(ClassTypeUtils.getTypeStr(char.class), "char"); Assert.assertEquals(ClassTypeUtils.getTypeStr(double.class), "double"); Assert.assertEquals(ClassTypeUtils.getTypeStr(float.class), "float"); Assert.assertEquals(ClassTypeUtils.getTypeStr(int.class), "int"); Assert.assertEquals(ClassTypeUtils.getTypeStr(long.class), "long"); Assert.assertEquals(ClassTypeUtils.getTypeStr(short.class), "short"); Assert.assertEquals(ClassTypeUtils.getTypeStr(void.class), "void"); class LocalType { } Assert.assertEquals(ClassTypeUtils.getTypeStr(anonymous.getClass()), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$1"); Assert.assertEquals(ClassTypeUtils.getTypeStr(LocalType.class), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$2LocalType"); Assert.assertEquals(ClassTypeUtils.getTypeStr(MemberClass.class), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$MemberClass"); Assert.assertEquals(ClassTypeUtils.getTypeStr(StaticClass.class), "com.alipay.sofa.rpc.common.utils.StaticClass"); Assert.assertEquals(ClassTypeUtils.getTypeStr(String[][][].class), "java.lang.String[][][]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(boolean[].class), "boolean[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(byte[].class), "byte[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(char[].class), "char[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(double[].class), "double[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(float[].class), "float[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(int[].class), "int[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(long[].class), "long[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(short[].class), "short[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(Array.newInstance(anonymous.getClass(), 2, 3).getClass()), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$1[][]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(LocalType[][].class), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$2LocalType[][]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(MemberClass[].class), "com.alipay.sofa.rpc.common.utils.ClassTypeUtilsTest$MemberClass[]"); Assert.assertEquals(ClassTypeUtils.getTypeStr(StaticClass[].class), "com.alipay.sofa.rpc.common.utils.StaticClass[]"); Assert.assertArrayEquals(ClassTypeUtils.getTypeStrs(new Class[] { String[].class }), new String[] { "java.lang.String[]" }); Assert.assertArrayEquals(ClassTypeUtils.getTypeStrs(new Class[] { String[].class }, false), new String[] { "java.lang.String[]" }); Assert.assertArrayEquals(ClassTypeUtils.getTypeStrs(new Class[] { String[].class }, true), new String[] { String[].class.getName() }); }