java - Is it possible to put methods in arrays to be randomized? -
i'm using java, , wondering if it's possible put methods directly arrays elements. like:
...[] arrayname = {herp(), derp(), jinkies()};
when looked prior, people mentioned "reflection," don't know (i'm new programming). there simple way put methods arrays (my goal spit them out randomly random, , terminate string parameter in each method named "quit" or something)? if not, how reflection work circumstance (if @ all)?
i not asking reflection is. exact (main) question "is possible put methods arrays," , if is, how done? what syntax it?
thank time
it not possible in java assign function object.
still can use use lambda expression or similar structure this. not assign functions can use one.
create functional interface
@functionalinterface interface myfunction { public void fun(); }
use lambda expressions initialize array of functional interfaces
myfunction[] functions = new myfunction[]{ () -> system.out.println("i herp"), () -> { int = 2; int b = 3; system.out.println(a + b); } };
use array array of functions.
functions[0].fun();
Comments
Post a Comment