java - Passing Class and Method as parameter -


i looking out way pass class , method both parameters method. have repetitive piece of code want reduce.

i want this:

public static void methodname(class c, method m ) {            c.m.sendkeys("item");                     } 

is possible?

in java 8 can use method references passed lambda;

methodname(c::m); 

you need specify type (arguments , return value) of function , use 1 of existing functional interfaces or define own.

if example function returns boolean , takes object of class t input, can use predefined functional interface predicate:

public static void methodname(item item, predicate<item> p) {     p.test(item);     // ... } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -