这段看不懂,老师
else if(annotation is Headers){
val headersArray = annotation.value
//@Headers("auth-token:token","accountId:123456")
for (header in headersArray){
val colon = header.indexOf(":")
check(!(colon==0||colon==-1)){
String.format(
"@headers value must be in the form [name:value] ,but found [%s]",
header
)
}
val name = header.substring(0, colon)
val value = header.substring(colon + 1).trim()
headers[name] = value
}
}else if (annotation is BaseUrl){
}
13
收起
正在回答 回答被采纳积分+1
1回答
LovelyChubby
2021-06-16 21:29:59
else if(annotation is Headers){
val headersArray = annotation.value
//@Headers("auth-token:token","accountId:123456")
取出方法上面标记的headers注解中的参数,它是个数组,且是key:value格式
下面是遍历这个数组
for (header in headersArray){
取出:所在的位置,如果是:不存在或在第0个位置,说明header格式不正确,则抛出异常
val colon = header.indexOf(":")
check(!(colon==0||colon==-1)){
String.format(
"@headers value must be in the form [name:value] ,but found [%s]",
header
)
}
这里是字符串截取了
val name = header.substring(0, colon)
val value = header.substring(colon + 1).trim()
headers[name] = value
}
}else if (annotation is BaseUrl){
}
提问者:lovejavacoff...
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星