【发布时间】:2019-07-17 15:00:46
【问题描述】:
我的 Kotlin 类 TimeUtils 有一个密封类声明为:
sealed class TimeUnit {
object Second : TimeUnit()
object Minute : TimeUnit()
fun setTimeOut(timeout : TimeUnit) {
// TODO something
}
我的 Java 类正在调用 setTimeOut 方法,例如:
TimeUtils obj = new TimeUtils();
if (some condition) {
obj.setTimeOut(TimeUtils.TimeUnit.Minute); // ERROR
} else if (some other condition) {
obj.setTimeOut(TimeUtils.TimeUnit.Second); // ERROR
}
我在上面两行声明 expression required 时遇到错误。
谁能帮忙解决一下?
【问题讨论】:
标签: java kotlin sealed-class