Last active
August 29, 2015 14:19
-
-
Save mike-rogers/8ed6ef1eaad982972107 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
class Programmer { | |
private String name; | |
public Programmer(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return this.name; | |
} | |
public void announce() { | |
System.out.println("I am a Programmer and my name is " + name); | |
} | |
} | |
class Pair { | |
private Programmer leftPerson; | |
private Programmer rightPerson; | |
public Pair(Programmer leftPerson, Programmer rightPerson) { | |
this.leftPerson = leftPerson; | |
this.rightPerson = rightPerson; | |
} | |
public void announce() { | |
System.out.println("We are pair-programming and our names are " + | |
this.leftPerson.getName() + | |
" and " + | |
this.rightPerson.getName()); | |
} | |
} | |
interface MockPopulator { | |
public void createMocksForPair(Programmer one, Programmer two); | |
} | |
public class JavaLambdaAsParameterExample { | |
private Pair createSamplePair(MockPopulator populator) { | |
Programmer mike = new Programmer("Mike"); | |
Programmer giules = new Programmer("Giules"); | |
Pair pair = new Pair(mike, giules); | |
populator.createMocksForPair(mike, giules); | |
return pair; | |
} | |
public void doTheThing() { | |
Pair pair = createSamplePair((left, right) -> { | |
left.announce(); | |
right.announce(); | |
}); | |
pair.announce(); | |
} | |
public static void main(String[] args) { | |
JavaLambdaAsParameterExample sample = new JavaLambdaAsParameterExample(); | |
sample.doTheThing(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: