可暂停且可为空

huangapple 未分类评论45阅读模式
英文:

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?

huangapple
  • 本文由 发表于 2020年7月26日 05:18:51
  • 转载请务必保留本文链接:https://java.coder-hub.com/63093663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定