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;
關(guān)鍵就是data的初始化,不初始化會報錯。求指導(dǎo)。
問題解答
回答1:List<? extends WeatherData> data = null;
或者想辦法把weatherENUM的某個值當作參數(shù)傳到dao
List<? extends WeatherData> data = weatherReportDao.getReportData(reportType,dataType);回答2:
定義成全局量就不用初始化了。
相關(guān)文章:
1. index.php錯誤,求指點2. python小白,問一個關(guān)于可變類型和不可變類型底層的問題3. html5 - qq空間播放視頻的返回數(shù)據(jù)4. python - PyQt5 如何獲得標題?5. node.js - 微信小程序 +nodejs+socket.io bug6. nginx和web服務(wù)都跑在docker容器里時,nginx負載均衡如何配置服務(wù)的IP地址7. MYSQL新建用戶設(shè)置可以遠程訪問的問題8. html5 - 微信退出程序,存儲和Cookie會丟失9. dict - Python判斷字典中是否有重復(fù)值10. html5 - 微信瀏覽器視頻播放失敗
