Use interface for method callbacks.
This way people can implement callback methods in java with lambdas.
When you want to call a java method with multiple arguments, right
now you have to say:
foo.method(arg1, arg2, new MethodCallback() {
public void onValues(type1 res1, type2 res2) {
...;
}
}
By changing MethodCallback from an anonymous class to an interface, we
can call the function with a Java 8 lambda instead.
foo.method(arg1, arg2, (res1, res2) -> res1 == OK ? setCallback(res2) : die(res1)));
Test: compiles
Bug: 33744648
Change-Id: I9b3aad019560714e2e6ffff0081c5d590f447cbc
diff --git a/generateJava.cpp b/generateJava.cpp
index 97c836e..6faf52d 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -222,13 +222,13 @@
const bool needsCallback = method->results().size() > 1;
if (needsCallback) {
- out << "\npublic abstract class "
+ out << "\npublic interface "
<< method->name()
<< "Callback {\n";
out.indent();
- out << "public abstract void onValues("
+ out << "public void onValues("
<< Method::GetJavaArgSignature(method->results())
<< ");\n";