你會怎樣用更多kotlinic的方式編寫下面的代碼?什麼時候應該使用let {},什麼時候只是簡單的!= null
var returnValue = ...
val s3data = presignedUrl.body()
if (s3data != null) {
val uploadImage = api.uploadImage(s3data.bucketUrl, s3data.awsAccessKeyId, s3data.policy, s3data.key, s3data.signature, body).execute()
if (!uploadImage.isSuccessful) {
crashReporterService.sendIssue("Failed uploading file", "Failed uploading file ${uploadImage.raw()}")
returnValue = Result.FAILURE
} else {
returnValue = Result.SUCCESS
}
} else {
crashReporterService.sendIssue("Failed uploading image", "Error - ${presignedUrl.raw()}")
returnValue = Result.FAILURE
}
return returnValue
我可以用讓,但我覺得它使代碼更復雜,難以理解
關於你的代碼的一個註釋:返回asap是一個很好的練習afaik,縮小範圍並簡化邏輯 – DPM