Java tutorial
//package com.java2s; import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class Main { public static String getType(Class<?> paramClass) { if (paramClass.isArray()) { return "[" + getDesc(paramClass.getComponentType()); } if (!paramClass.isPrimitive()) { return paramClass.getName().replaceAll("\\.", "/"); } return getPrimitiveLetter(paramClass); } public static String getDesc(Class<?> paramClass) { if (paramClass.isPrimitive()) { return getPrimitiveLetter(paramClass); } if (paramClass.isArray()) { return "[" + getDesc(paramClass.getComponentType()); } return "L" + getType(paramClass) + ";"; } public static String getDesc(Constructor<?> paramConstructor) { StringBuffer localStringBuffer = new StringBuffer(); localStringBuffer.append("("); Class[] arrayOfClass = paramConstructor.getParameterTypes(); for (int i = 0; i < arrayOfClass.length; i++) { localStringBuffer.append(getDesc(arrayOfClass[i])); } localStringBuffer.append(")V"); return localStringBuffer.toString(); } public static String getDesc(Method paramMethod) { StringBuffer localStringBuffer = new StringBuffer(); localStringBuffer.append("("); Class[] arrayOfClass = paramMethod.getParameterTypes(); for (int i = 0; i < arrayOfClass.length; i++) { localStringBuffer.append(getDesc(arrayOfClass[i])); } localStringBuffer.append(")"); localStringBuffer.append(getDesc(paramMethod.getReturnType())); return localStringBuffer.toString(); } public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; } if (Void.TYPE.equals(paramClass)) { return "V"; } if (Boolean.TYPE.equals(paramClass)) { return "Z"; } if (Character.TYPE.equals(paramClass)) { return "C"; } if (Byte.TYPE.equals(paramClass)) { return "B"; } if (Short.TYPE.equals(paramClass)) { return "S"; } if (Float.TYPE.equals(paramClass)) { return "F"; } if (Long.TYPE.equals(paramClass)) { return "J"; } if (Double.TYPE.equals(paramClass)) { return "D"; } throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type"); } }