title: Using future.onComplete with Java and Akka and a different Result as String
body: <p>I have the following question... </p>
  
  <p>I'm using Akka 2.3.6 from Java and would like to get the following done:</p>
  
  <pre><code>Future&lt;Object&gt; future = ask(actor, new GetPOIDataMessage(tenant), Timeout.durationToTimeout(duration));
      future.onSuccess(new OnComplete&lt;NonSimpleObject&gt;() {
                            public void onComplete(Throwable failure, final NonSimpleObject data) {
                                if (failure != null) {
                                    deferredResult.setErrorResult("An error occured during the request");
                                } else {
                                    deferredResult.setResult(data);
                                }
                            }
                        }, ec);
  </code></pre>
  
  <p>NonSimpleObject is the type of the message sent back from the actor. I get the following error compiling my code:</p>
  
  <pre><code>error: method onSuccess in interface Future&lt;T&gt; cannot be applied to given types;
  [error]         future.onSuccess(new OnComplete&lt;NonSimpleObject&gt;() {    
  [error]               ^
  [error]   required: PartialFunction&lt;Object,U&gt;,ExecutionContext
  [error]   found: &lt;anonymous OnComplete&lt; NonSimpleObject &gt;&gt;,ExecutionContext
  [error]   reason: cannot infer type-variable(s) U
  [error]     (argument mismatch; &lt;anonymous OnComplete&lt; NonSimpleObject &gt;&gt; cannot be converted to PartialFunction&lt;Object,U&gt;)
  [error]   where U,T are type-variables:
  [error]     U extends Object declared in method &lt;U&gt;onSuccess(PartialFunction&lt;T,U&gt;,ExecutionContext)
  [error]     T extends Object declared in interface Future`
  </code></pre>
  
  <p>which I fail to decode. Seems to be over my head right now.
  It works fine with a String as the result. I could not find other examples on the web that are using something different as a String.</p>
  
  <p>Thanks for any pointers in the right direction. Jan</p>