list - java代码优化

查看:121
本文介绍了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的初始化,不初始化会报错。求指导。

解决方案

List<? extends WeatherData> data = null;

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

List<? extends WeatherData> data =  weatherReportDao.getReportData(reportType,dataType);

这篇关于list - java代码优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆