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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -