Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Main {
public static void main(String[] args) {
Box<Integer> box1 = new Box<Integer>(100);
System.out.println(box1.takeOut()); // 100
System.out.println(box1.takeOut(
new IBinaryOp<Integer, Integer>() {
public Integer apply(Integer a, Integer b) {
return a + b;
}
},
200)); // 300
System.out.println(box1.takeOut(
new IBinaryOp<Integer, String>() {
public String apply(Integer a, String b) {
return a + b;
}
},
"")); // 100円
Box<String> box2 = new Box<String>("");
System.out.println(box2.takeOut()); //
System.out.println(box2.takeOut(
new IBinaryOp<String, String>() {
public String apply(String a, String b) {
return a + b;
}
},
"")); // 百円
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment