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 - pyspider爬pdf爬了一小段时间后就不动了2. javascript - Ajax加载Json时,移动端页面向左上角缩小一截儿,加载完成后才正常显示,这该如何解决?3. python运行后没有任何反馈要怎么排查4. python中怎么对列表以区间进行统计?5. 如何合并两张具有相同结构的mysql表6. javascript - h5 video层级太高导致浮在div上面,如何解决?7. linux - Ubuntu下编译Vim8(+python)无数次编译失败8. mysql ER_BAD_DB_ERROR: Unknown database ’test’9. html5 - video ios不能播放怎么办?10. mysql - 记得以前在哪里看过一个估算时间的网站
