英文:
Suspendable with Nullable
问题
我需要将可中断的函数设置为Nullable。期望的行为是,当我调用该函数时,如果它是一个错误的响应体,它应该简单地返回null
,而不是抛出HttpException
。
@GET("product")
suspend fun getProduct(): Product?
是否可能?如果是,我该如何做到这一点?
英文:
I need to make the suspendable function Nullable. The expected behavior is, when I call the function, If it's an error body, It should simply return null
rather than throwing HttpException
.
@GET("product")
suspend fun getProduct(): Product?
Is it possible? If yes, how can I do that?
专注分享java语言的经验与见解,让所有开发者获益!
评论