search

Home  >  Q&A  >  body text

list - java code optimization

The current version can run, but it must be poorly written.

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;

The key is the initialization of data. If not initialized, an error will be reported. Ask for guidance.

PHP中文网PHP中文网2775 days ago650

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-17 10:10:39

    List<? extends WeatherData> data = null;
    

    Or find a way to pass a certain value of weatherENUM as a parameter to dao

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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-17 10:10:39

    If defined as a global variable, there is no need to initialize it.

    reply
    0
  • Cancelreply