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. PHP类中的$this2. css - 新手做响应式布局, 断点过后右侧出现空白,求帮助,谢谢。3. 前端 - css3中,这样的代码为什么会显示成图片?4. javascript - nodejs 如何同步执行某些模块函数?5. python - 如何1次执行多条SQL语句6. javascript - 正则的截取匹配问题求助7. javascript - webpack dllPlugin 是不是只用于开发环境?8. javascript - QQ第三方登录的问题9. Python中使用超长的List导致内存占用过大10. html - 如何用浏览器打开微信分享出去的链接
