I have the below method in which the arguments to be passed to the method vary according to the value of the ENUM which is passed as the 1st argument.
public void startReporter(ReportType reportType, long period, Class className) {
reportHandler = new ReportHandler(metricRegistry);
switch (reportType) {
case CONSOLE_REPORTER:
reportHandler.startConsoleReport(period);
break;
case SLF4J_REPORTER:
reportHandler.startSLF4JReport(className,period);
break;
case JMX_REPORTER:
reportHandler.startJMXReport();
}
}
As you can see, not all the arguments that are passed are used in all cases in the switch statement. What is the best way to address this scenario? I do not want to have 3 methods. I need to do this with only this method.
Aucun commentaire:
Enregistrer un commentaire