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?
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.