Last active
October 26, 2016 19:28
-
-
Save oscarryz/3ca018ab84d82641b9c6cd76fffc9c28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.BiConsumer; | |
import java.util.Arrays; | |
import java.util.List; | |
class SimpleClass { | |
void methodA(String a, String b) { | |
System.out.printf("%s %s%n", a, b); | |
} | |
} | |
class B { | |
void different(String x, String y) { | |
System.out.println( | |
new StringBuilder(y).append(x).reverse().toString() | |
); | |
} | |
} | |
class Service { | |
void doService(List<BiConsumer<String,String>> methods ) { | |
// this is equivalent to the 'for' below | |
methods.forEach( item -> item.accept("hello", "world")); | |
//for( BiConsumer<String,String> item : methods ) { | |
// item.accept("Hello", "world"); | |
//} | |
} | |
} | |
class Main { | |
public static void main( String ... args ) { | |
SimpleClass sc = new SimpleClass(); | |
B b = new B(); | |
Service s = new Service(); | |
List<BiConsumer<String,String>> collection = Arrays.asList( | |
sc::methodA, | |
b::different | |
); | |
s.doService( collection ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment