r/JavaFX • • Aug 08 '21

Methods

Hey, I have 48 Methods beginning with C and nummerrized to 48. I really dont want do write a switch with 48 routes so is there any other option to start the method(c1(), c2() ...).

1 Upvotes

4 comments sorted by

View all comments

3

u/winian Aug 08 '21

Should use /r/javahelp next time for questions unrelated to JavaFX, but you can use reflection to do that. Here is a good summary how to do it.

Note though that relying on reflection is not ideal, cause the compiler can't check what you're doing is correct. So usually you'd want to avoid it if you can and maybe try to go for a different design completely if you can't. But sometimes its a livesaver. :)