获得方法集合
public class Transform {
public static final HashMap<Type, Method> METHOD_MAP = new HashMap<>();
static {
Method[] methods = Transform.class.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method declaredMethod = methods[i];
if (!declaredMethod.getName().startsWith("transform")) {
continue;
}
String code = declaredMethod.getName().substring("transform".length()).toUpperCase();
Type annotationTypeEnum = Type.getByCode(code);
declaredMethod.setAccessible(true);
METHOD_MAP.put(annotationTypeEnum, declaredMethod);
}
}
private static String methodA(){
return null;
}
}
调用此方法
Method method = Transform.METHOD_MAP.get(Type);
String result = (Result) method.invoke(null, jsonStr, Type);