Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created February 27, 2010 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/316380 to your computer and use it in GitHub Desktop.
Save jutememo/316380 to your computer and use it in GitHub Desktop.
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