在这段生成的适配器处理外部载荷前进行审查。
调用允许列表中的一个解码器,显式表达输入类型与完整输出类型,保留有用的失败信息,并复用已验证的反射元数据和无状态解码器实例。
Java
import java.lang.reflect.Method;
import java.util.List;
public class GeneratedDecoder {
@SuppressWarnings("unchecked")
static List<String> decodeNames(
String className, String methodName, Object input) {
try {
Class<?> type = Class.forName(className);
Object codec = type.getDeclaredConstructor().newInstance();
Method method = type.getDeclaredMethod(methodName, input.getClass());
method.setAccessible(true);
Object result = method.invoke(codec, input);
return (List<String>) result;
} catch (Exception error) {
return null;
}
}
}
生成代码仅作示例,不代表任何特定模型