list - java代碼優(yōu)化
問(wèn)題描述
現(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)。
問(wèn)題解答
回答1:List<? extends WeatherData> data = null;
或者想辦法把weatherENUM的某個(gè)值當(dāng)作參數(shù)傳到dao
List<? extends WeatherData> data = weatherReportDao.getReportData(reportType,dataType);回答2:
定義成全局量就不用初始化了。
相關(guān)文章:
1. android - weex 項(xiàng)目createInstanceReferenceError: Vue is not defined2. PHPExcel表格導(dǎo)入數(shù)據(jù)庫(kù)怎么導(dǎo)入3. android - 哪位大神知道java后臺(tái)的api接口的對(duì)象傳到前端后輸入日期報(bào)錯(cuò),是什么情況?求大神指點(diǎn)4. javascript - 如圖,百度首頁(yè),查看源代碼為什么什么都沒(méi)有?5. pdo 寫入到數(shù)據(jù)庫(kù)的內(nèi)容為中文的時(shí)候?qū)懭雭y碼6. vue2.0+webpack 如何使用bootstrap?7. html - 根據(jù)用戶id實(shí)現(xiàn)論壇用戶頭像顯示的最佳實(shí)現(xiàn)8. 前端 - 為什么CSS transform-origin 屬性在 Chrome 和 Safari 中得到完全不同的效果?9. docker綁定了nginx端口 外部訪問(wèn)不到10. PHP類封裝的插入數(shù)據(jù),總是插入不成功,返回false;
