I have Java code that roughly goes like this:
public String render(String str) {
byte[] b = [serialize str]
client.sendRequest(b, new Callback<byte[]>() {
@Override
public void onDone(byte[] data) {
String res = [convert data back to String]
// TODO: return this string in the outer function
});
return "???";
}
I'm having issues getting the render function to return the String that I obtain from the onDone callback. I tried initializing the String res outside of the sendRequest invocation but I run into issues with the variable not being final.
I was also reading up on Java Futures here. From that I was thinking I could set a Future and call isDone() on it to make sure it was set? However this code seems verbose and I was wondering if there was a simpler solution.