Home | History | Annotate | Download | only in base
      1 // Copyright 2015 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 package org.chromium.base;
      6 
      7 import org.chromium.base.annotations.CalledByNative;
      8 
      9 /**
     10  * A simple single-argument callback to handle the result of a computation.
     11  *
     12  * @param <T> The type of the computation's result.
     13  */
     14 public abstract class Callback<T> {
     15     /**
     16      * Invoked with the result of a computation.
     17      */
     18     public abstract void onResult(T result);
     19 
     20     @SuppressWarnings("unchecked")
     21     @CalledByNative
     22     private void onResultFromNative(Object result) {
     23         onResult((T) result);
     24     }
     25 
     26     @SuppressWarnings("unchecked")
     27     @CalledByNative
     28     private void onResultFromNative(boolean result) {
     29         onResult((T) Boolean.valueOf(result));
     30     }
     31 
     32     @SuppressWarnings("unchecked")
     33     @CalledByNative
     34     private void onResultFromNative(int result) {
     35         onResult((T) Integer.valueOf(result));
     36     }
     37 }
     38