缺少强转导致的编译器错误一例 - 点滴记忆*记忆点滴
收藏本站

缺少强转导致的编译器错误一例

 Jwt jwt = parse(compact);
        if (jwt instanceof Jws) {
            Jws jws = (Jws) jwt;
            Object body = jws.getBody();
            if (body instanceof Claims) {
                return handler.onClaimsJws((Jws<Claims>) jws);
            } else {
                return handler.onPlaintextJws((Jws<String>) jws);
            }
        }
强转代码

 Jwt jwt = parse(compact);
        if (jwt instanceof Jws) {
            Jws jws = (Jws) jwt;
            Object body = jws.getBody();
            if (body instanceof Claims) {
                return handler.onClaimsJws(jws);
            } else {
                return handler.onPlaintextJws(jws);
            }
        }
去掉强转代码,方法声明

T onClaimsJws(Jws<Claims> jws);


eclipse 编译正常,不报错。

maven 编译报:

    不兼容的类型: java.lang.Object无法转换为T


原因eclipse 编译器检查不如javac 严格


    留下足迹