在lambda表達式中使用的變量應(yīng)該是最終變量或有效的最終變量。在lambda表達式中使用的變量應(yīng)該是最終變量或有效的最終變量。當(dāng)我試圖用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條經(jīng)驗 獲得超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();
而不使用其返回值 帶著任務(wù) calTz = TimeZone.getTimeZone(v.getTimeZoneId().getValue());
您不會修改最初傳遞的 calTz
而且你沒有在這個方法中使用它 你總是回來 null
,你為什么不 void
作為返回類型?

德瑪西亞99
TA貢獻1770條經(jīng)驗 獲得超3個贊
對有效的最終變量的限制禁止訪問動態(tài)變化的局部變量,這些局部變量的捕獲可能會帶來并發(fā)問題。

蝴蝶刀刀
TA貢獻1801條經(jīng)驗 獲得超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
提交
取消