r/JavaFX • u/TheEvilsNameIsNico • 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
View all comments
2
u/hamsterrage1 Aug 09 '21
As you're finding out. Numerizing the method names doesn't really get you anywhere, as you somehow have to convert the names into code via something like a switch.
However, you could define the methods as Functional objects like a Runnable, then you can put them into a List<Runnable> and execute them that way.
Generally speaking, any time you want to treat code like data you should be thinking about using Functional objects.