I want to do something like this:

fun process(minutes: Int) = 0

fun test() {
    process(System.currentTimeMillis() / 1000 / 60) // error: Int expected
}

如果我try process((System.currentTimeMillis() / 1000 / 60) as Int),我在运行时会得到ClassCastException.

So how can I convert Long to Int?

推荐答案

Use Long.toInt():

process((System.currentTimeMillis() / 1000 / 60).toInt()) 

Kotlin相关问答推荐

使数组变量在Kotlin中作为数组从意图传递到另一个活动

插入/更新/upsert时不发出房间流

Android Studio中的只读集合不支持操作失败的原因是什么?

两个LocalDateTime之间的Kotlin差异

在Kotlin lambda的参数中如何指定函数类型?

Kotlin .如何用从 1 到 90 的 5 个唯一数字填充列表中的每一行?

内容更改后的 var 重新计算

如何通过 compose 处理剪切区域?

如何从 kotlin 中的数据类访问 val?

错误:cannot find symbol import com.gourav.news.databinding.ActivityDetailBindingImpl;

Kotlin 代码是如何编译成原生代码的?

`this@classname` 在 Kotlin 中是什么意思?

Kotlin boxed Int 不一样

Kotlin解构when/if语句

Tornadofx - 如何在每个实例上将参数传递给 Fragment

如何在Android Studio 4.1中默认启用Kotlin Android扩展

以Kotlin为单位的货币数据类型

如何将vararg作为数组传递给Kotlin中的函数?

将字符串编码为Kotlin中的UTF-8

判断EditText是否为空kotlin android