list - java代碼優(yōu)化
問題描述
現(xiàn)在的能跑,但是肯定寫的不好。
List<? extends WeatherData> data = weatherReportDao.getCoviReportData(reportType);WeatherENUM weatherENUM = WeatherENUM.valueOf(reportFunction);switch (weatherENUM){ case atmosphere:data = atmosphereReportDao.getAtmosphereReportData(reportType);break; case covi: data = weatherReportDao.getCoviReportData(reportType);break; case windSpeed:data = windSpeedReportDao.getWindSpeedReportData(reportType);break;}return data;
關鍵就是data的初始化,不初始化會報錯。求指導。
問題解答
回答1:List<? extends WeatherData> data = null;
或者想辦法把weatherENUM的某個值當作參數(shù)傳到dao
List<? extends WeatherData> data = weatherReportDao.getReportData(reportType,dataType);回答2:
定義成全局量就不用初始化了。
相關文章:
1. javascript - immutable配合react提升性能?2. javascript - sublime快鍵鍵問題3. javascript - nodejs關于進程間發(fā)送句柄的一點疑問4. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務器還是不能訪問?5. 實現(xiàn)bing搜索工具urlAPI提交6. javascript - 移動端上不能實現(xiàn)拖拽布局嗎?7. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化8. phpstudy8.1支持win11系統(tǒng)嗎?9. 配置Apache時,添加對PHP的支持時語法錯誤10. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~

網(wǎng)公網(wǎng)安備