Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重学 Java 设计模式:实战适配器模式「从多个MQ消息体中,抽取指定字段值场景」 #312

Open
lulufeiacount opened this issue May 27, 2022 · 0 comments

Comments

@lulufeiacount
Copy link

笔误:

public class RebateInfo {

    private String userId;  // 用户ID
    private String bizId;   // 业务ID
    private Date bizTime;   // 业务时间
    private String desc;    // 业务描述
    
    // ... get/set
}
    public static RebateInfo filter(Map obj, Map<String, String> link) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        RebateInfo rebateInfo = new RebateInfo();
        for (String key : link.keySet()) {
            Object val = obj.get(link.get(key));
            RebateInfo.class.getMethod("set"   key.substring(0, 1).toUpperCase()   key.substring(1), String.class).invoke(rebateInfo, val.toString());
        }
        return rebateInfo;
    }

RebateInfo 类中的bizTimeDate类型,没法通在反射的时候指定参数类型为String调用此方法,会出现java.lang.NoSuchMethodException: 异常,应该是需要把bizTime定义为String类型吧,,亦或是如果需要做到适配其它类型的话,怎么做比较好一点呢?例如Integer/Double等等

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant