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的初始化,不初始化会报错。求指导。

阅读 3k
2 个回答
List<? extends WeatherData> data = null;

或者想办法把weatherENUM的某个值当作参数传到dao

List<? extends WeatherData> data =  weatherReportDao.getReportData(reportType,dataType);
新手上路,请多包涵

定义成全局量就不用初始化了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题