【问题标题】:How to get class name from parameter function in retrofit如何从改造中的参数函数中获取类名
【发布时间】:2021-01-19 12:23:04
【问题描述】:

改造中如何从参数函数中获取类名? 这是行不通的。 谢谢。

test(TestClass.class);
        
private void test(Class className) {

    getData().enqueue(new Callback<className>() {
        @Override
        public void onResponse(Call<className> call,Response<className> response) {
        }

        @Override
        public void onFailure(Call<className> call, Throwable t) {
            t.printStackTrace();
        }
    });
}

【问题讨论】:

    标签: java android function class retrofit


    【解决方案1】:

    试试这个:

    public class User {  
        private int id;
        private String email;
        private String username;
    }
    
    ...
    
    Call<User> call = userService.login();  
    call.enqueue(new Callback<User>() {  
        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            // todo deal with returned data (user)
        }
    
        public void onFailure(Call<User> call, Throwable t) {
            // todo deal with the failed network request
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-18
      • 2020-02-14
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多