Skip to main content
edited body
Source Link
ppeterka
  • 20.8k
  • 6
  • 67
  • 80

Provided this is Java, you could use reflection if you really wanted that...

return Class.forName("packageName.Listener"+theNumber).newIsntancenewInstance(); 

Of course, doing so might have adverse effects too - performance hit, ugly code, debugging and readability issues, having to deal with handling multiple kinds of exceptions...

Recommended reading:

Provided this is Java, you could use reflection if you really wanted that...

return Class.forName("packageName.Listener"+theNumber).newIsntance(); 

Of course, doing so might have adverse effects too - performance hit, ugly code, debugging and readability issues, having to deal with handling multiple kinds of exceptions...

Provided this is Java, you could use reflection if you really wanted that...

return Class.forName("packageName.Listener"+theNumber).newInstance(); 

Of course, doing so might have adverse effects too - performance hit, ugly code, debugging and readability issues, having to deal with handling multiple kinds of exceptions...

Recommended reading:

Source Link
ppeterka
  • 20.8k
  • 6
  • 67
  • 80

Provided this is Java, you could use reflection if you really wanted that...

return Class.forName("packageName.Listener"+theNumber).newIsntance(); 

Of course, doing so might have adverse effects too - performance hit, ugly code, debugging and readability issues, having to deal with handling multiple kinds of exceptions...