如何将Kotlin中的Long转换为Int?
我想要做这样的事情:
fun process(minutes: Int) = 0 fun test() { process(System.currentTimeMillis() / 1000 / 60) // error: Int expected }
如果我尝试process((System.currentTimeMillis() / 1000 / 60) as Int)
我在运行时得到一个ClassCastException
。
那么如何将Long转换为Int?
使用Long.toInt()
:
process((System.currentTimeMillis() / 1000 / 60).toInt())
- 匕首2:具有相同键的多个条目
- Osmdroid&Osmdroid bonuspack如何使用CacheManager
- Kotlin IllegalStateException:在类路径中找不到资源:kotlin / .kotlin_string_table
- Kotlin:双冒号(反射)运算符结束
- 得到未解决的参考:将java转换为kotlin时的setText
- 为什么不重新安排在Intellij Kotlin文件中的代码工作?
- 什么是合法的方式来通过反射获得纯Kotlin财产的注释,他们总是失踪?
- Kotlin生成构造函数,将默认值设置为无参数
- ControlsFX SpreadsheetView rowspan IndexOutOfBoundsException