【发布时间】:2017-09-15 15:55:10
【问题描述】:
我是 Retrofit2 的新手。我在阅读this site时有一个问题。
为什么ServiceGenerator中的the createService method不是无限递归的?
public static <S> S createService(
Class<S> serviceClass, String username, String password) {
if (!TextUtils.isEmpty(username)
&& !TextUtils.isEmpty(password)) {
String authToken = Credentials.basic(username, password);
return createService(serviceClass, authToken);
}
return createService(serviceClass, null, null);
}
【问题讨论】:
-
也许你可以不做
//omitted,而只是给我们看实际的代码? -
可能是因为 TextUtils.isEmpty(null) 的计算结果为 false,并且在“第二次”传递中调用了第一个返回语句...
-
@Gotiasits No. TextUtils.isEmpty(null) 返回 true。
-
这实际上看起来像是他们的代码中的错误。