Java enum variables cannot be defined repeatedly in cases?
黄舟
黄舟 2017-05-17 10:09:15
0
1
886

I need to assign a value to a variable based on the string content, but the variable type is different. I am now

        switch (weatherENUM){
            case weather:
               List<CoviData> data =  weathreService.getCoviData(reportType);
                break;
            case COVI:
                List<helloData> data =  weathreService.gethelloData(reportType);
        }

Idea reported an error and repeated the definition. But this is an enumeration and will not be repeated. How do I accomplish my goal?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
大家讲道理

CoviData and HelloData can inherit the parent class Data at the same time, and use qualified type wildcards to declare objects.
List<? extends Data> data. Remember to declare it outside of switch.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!