Created
February 27, 2010 01:28
-
-
Save jutememo/316380 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
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