title: Java callback functions as parameter
body: <p>I'd like to do something simple, but I can't express it in a google search. So, I come here ^^</p>
  
  <p>I have an Async task like this :</p>
  
  <pre><code>class RequestTask extends AsyncTask&lt;String, String, String&gt; {
  
      final MyCallbackInterface callback;
  
      RequestTask(MyCallbackInterface callback) {
          this.callback = callback;
      }
  
      @Override
      protected String doInBackground(String... uri) {
          ...
      }
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
          callback.onTaskFinished(result);
      }
  }
  
  interface MyCallbackInterface {
      void onTaskFinished(String result);
  }
  </code></pre>
  
  <p>So, I have a task with a callback to execute when the task ends.</p>
  
  <p>Now I can call it like this :</p>
  
  <pre><code>class Program {
  
      public void DoAsyncRequest(String stringUrl, MyCallbackInterface callback) {
          new RequestTask(callback).execute(stringUrl);
      }
  
      public static void Main(){
  
          DoAsyncRequest("http://toto.com", new MyCallbackInterface() {
  
              @Override
              public void onDownloadFinished(String result) {
                  //do something ...
              }
          });
      }
  }
  </code></pre>
  
  <p>But, instead of having an "inline" function as callback, is it possible to do something like this : (if yes, how ?)</p>
  
  <pre><code>class Program {
  
      public void DoAsyncRequest(String stringUrl, MyCallbackInterface callback) {
          new RequestTask(callback).execute(stringUrl);
      }
  
      public static void Main(){
  
           DoAsyncRequest("http://toto.com", MyCallBack);
      }
  
      private void MyCallBack(string result){
          //do something
      }
  }
  </code></pre>
  
  <p>Thanks!</p>