等号运算符不能在原始和盒装变量之间应用
在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 }
- Kapt generatestubs – 不能用单元测试的内部构造函数初始化对象
- 在BottomsheetDialog中使用setcontentview时,会出现类似“以下函数都不能用提供的参数调用”的错误
- Apache Tomcat 8.0无法加载使用Eclipse for Java EE,Mars 2编写的Kotlin中的servlet类
- 将Scala函数转换为Kotlin函数
- Kotlin parcelable和arrayList of parcelables
- Kotlin接口中的伴随对象
- 将数据从PendingIntent(AlarmManager)传递给BroadcastReceiver
- 如何实施一个有限的调用与改造阻塞客户端和协程
- 从Delegate属性的getValue()和setValue()函数外部获取KProperty信息
- Kotlin:创建扩展函数文件?加
- 动态生成的textview如何在kotlin中做findViewByTag它显示无法解析的引用