您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Javalambda表达式中使用的变量应该是final或有效的final

Javalambda表达式中使用的变量应该是final或有效的final

final可变装置,它可以被实例化一次。在Java中,你不能在lambda以及匿名内部类中使用非最终变量。

你可以使用旧的for-each循环来重构代码

private TimeZone extractCalendarTimeZoneComponent(Calendar cal,TimeZone calTz) {
    try {
        for(Component component : cal.getComponents().getComponents("VTIMEZONE")) {
        VTimeZone v = (VTimeZone) component;
           v.getTimeZoneId();
           if(calTz==null) {
               calTz = TimeZone.getTimeZone(v.getTimeZoneId().getValue());
           }
        }
    } catch (Exception e) {
        log.warn("Unable to determine ical timezone", e);
    }
    return null;
}

即使我对这段代码有些不了解:

java 2022/1/1 18:24:53 有586人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶