list - java代碼優化
問題描述
現在的能跑,但是肯定寫的不好。
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的某個值當作參數傳到dao
List<? extends WeatherData> data = weatherReportDao.getReportData(reportType,dataType);回答2:
定義成全局量就不用初始化了。
相關文章:
1. python - Django有哪些成功項目?2. 實現bing搜索工具urlAPI提交3. Python從URL中提取域名4. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)5. 關于mysql聯合查詢一對多的顯示結果問題6. 數據庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。7. node.js - 微信小程序websocket連接問題8. 直接打字符不可以嗎?>和>有區別嗎9. node.js - windows10下的npm全局路徑的復原或者將npm徹底刪除?10. Python中使用超長的List導致內存占用過大
