在lambda表达式中使用的变量应该是最终变量或有效的最终变量。在lambda表达式中使用的变量应该是最终变量或有效的最终变量。当我试图用calTz它显示了这个错误。private TimeZone extractCalendarTimeZoneComponent(Calendar cal,TimeZone calTz) {
try {
cal.getComponents().getComponents("VTIMEZONE").forEach(component->{
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;}
3 回答

MMTTMM
TA贡献1869条经验 获得超4个赞
A final
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;}
你叫. v.getTimeZoneId();
而不使用其返回值 带着任务 calTz = TimeZone.getTimeZone(v.getTimeZoneId().getValue());
您不会修改最初传递的 calTz
而且你没有在这个方法中使用它 你总是回来 null
,你为什么不 void
作为返回类型?

蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
private TimeZone extractCalendarTimeZoneComponent(Calendar cal,TimeZone calTz) { final AtomicReference<TimeZone> reference = new AtomicReference<>(); try { cal.getComponents().getComponents("VTIMEZONE").forEach(component->{ VTimeZone v = (VTimeZone) component; v.getTimeZoneId(); if(reference.get()==null) { reference.set(TimeZone.getTimeZone(v.getTimeZoneId().getValue())); } }); } catch (Exception e) { //log.warn("Unable to determine ical timezone", e); } return reference.get();}
添加回答
举报
0/150
提交
取消