参数类型; double?'可以将分配给参数类型' num',即使我检查值是否不是null
我有此功能:
double discount() {
return cost_min_discounted != null ? cost_min - cost_min_discounted : 0;
}
cost_min_discounted
定义为double?
我得到错误:
参数类型'double?'无法分配给参数类型 'num'
编写这样的代码的最佳方法是什么?我检查了空值,因此代码对我来说似乎是正确的。
I have this function:
double discount() {
return cost_min_discounted != null ? cost_min - cost_min_discounted : 0;
}
cost_min_discounted
is defined as double?
I get the error:
The argument type 'double?' can't be assigned to the parameter type
'num'
What's the best way to write code like that? I check for the null value, so the code seems correct to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您已经在开始时检查NULL时,在最后使用
!
。While you've already checking null at beginning, use
!
at the end.