summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/CallbacksTest.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/java/CallbacksTest.java b/java/CallbacksTest.java
new file mode 100644
index 0000000..8a4d73f
--- /dev/null
+++ b/java/CallbacksTest.java
@@ -0,0 +1,29 @@
+
+abstract class Callback<TRet, TParam>
+{
+ public abstract TRet call(TParam p);
+}
+
+class Caller
+{
+ private Integer doCall(String s, Callback<Integer, String> cb)
+ {
+ return cb.call(s);
+ }
+
+ public Integer convert(final String s)
+ {
+ return doCall(s, new Callback<Integer, String>() {
+ public Integer call(String s) { return Integer.parseInt(s); }
+ });
+ }
+}
+
+public class CallbacksTest
+{
+ public static void main(String [] args )
+ {
+ Caller c = new Caller();
+ System.out.println(c.getClass().getName() + " " + c.convert("666"));
+ }
+}