2015-12-11 116 views
0

我使用一個機器人項目作爲我的理解一個參考,在那裏,我發現這個界面:什麼是HttpCallback <T>中的目的和什麼是T?

public interface HttpCallback<T> { 
    void onSuccess(T var1); 

    void onHttpError(ResponseStatus var1); 
} 

Main Activity它實現了HttpCallback<UserDetails>參照此接口。

我的問題是,我不能得到什麼是T?請建議我在HttpCallback<T>代表什麼是T

//主要活動代碼:

public class MainActivity extends HttpCallback<UserDetails> { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     ... 
     } 

     HttpCallback<UserDetails> userDetailCallback = new HttpCallback<UserDetails>() { 
     @Override 
     public void onSuccess(UserDetails userDetails) { 
      setProgressVisibility(R.id.button_find_user, View.INVISIBLE); 

       if(!"ok".equals(addressDetails.errorMsg)){ 
       showErrorMessage("UserDetails Error", userDetails.errorMsg); 
       return; 
      } 
     } 

     @Override 
     public void onHttpError(ResponseStatus responseStatus) { 
      setProgressVisibility(R.id.button_find_user, View.INVISIBLE); 
      showErrorMessage("Internet Connection Problem", "Please check your Internet connection then try again."); 
     } 
    }; 
} 

謝謝。

+1

閱讀上Java泛型:HTTP:/ /stackoverflow.com/questions/15888551/how-to-interpret-public-tt-readobjectdata-classt-type-in​​-java – rafid059

+0

閱讀:https://docs.oracle.com/javase/tutorial/java/generics/types .html –

+0

謝謝@AshshinGhazi –

回答

1

T是什麼,但一個類型....它Generics..saying,它可以接受類型的任何對象...閱讀泛型在Java中瞭解更多詳情

+0

這真的有幫助,謝謝 –