等号运算符不能在原始和盒装variables之间应用
在Kotlin中,像这样将一些Long值与0比较是微不足道的。
if (firstUnread == 0) { return }
但通常会发生此错误。 什么是比较这些值的最佳方法?
运算符“==”不能应用于“长”和“整数”
0是Kotlin的Int
。 尝试用0L
代替它,它会工作。
在Kotlin中,数字没有隐含的扩展转换: https : //kotlinlang.org/docs/reference/basic-types.html
在你的代码中,你试图比较一个Long
( firstUnread
)和一个Int
( 0
)。 相反,比较0L
所以你是比较Long
与Long.
你可以在任何int数之后轻松地添加.toLong()
方法。 只需将您的代码更改为:
if (firstUnread == 0.toLong()) { return }