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的初始化,不初始化會(huì)報(bào)錯(cuò)。求指導(dǎo)。
問題解答
回答1:List<? extends WeatherData> data = null;
或者想辦法把weatherENUM的某個(gè)值當(dāng)作參數(shù)傳到dao
List<? extends WeatherData> data = weatherReportDao.getReportData(reportType,dataType);回答2:
定義成全局量就不用初始化了。
相關(guān)文章:
1. linux - Ubuntu下編譯Vim8(+python)無數(shù)次編譯失敗2. javascript - Ajax加載Json時(shí),移動(dòng)端頁面向左上角縮小一截兒,加載完成后才正常顯示,這該如何解決?3. python - pyspider爬pdf爬了一小段時(shí)間后就不動(dòng)了4. python中怎么對(duì)列表以區(qū)間進(jìn)行統(tǒng)計(jì)?5. mysql - 記得以前在哪里看過一個(gè)估算時(shí)間的網(wǎng)站6. javascript - h5 video層級(jí)太高導(dǎo)致浮在div上面,如何解決?7. mysql ER_BAD_DB_ERROR: Unknown database ’test’8. css - 請(qǐng)問B站頂部的模糊半透明導(dǎo)航條是怎么實(shí)現(xiàn)的呢?9. 如何合并兩張具有相同結(jié)構(gòu)的mysql表10. python運(yùn)行后沒有任何反饋要怎么排查
