小编Ant*_*t20的帖子

如何在Kotlin同时捕获许多例外

try { 

} catch (ex: MyException1, MyException2 ) {
    logger.warn("", ex)
}
Run Code Online (Sandbox Code Playgroud)

要么

try { 

} catch (ex: MyException1 | MyException2 ) {
    logger.warn("", ex)
}
Run Code Online (Sandbox Code Playgroud)

结果,编译错误:Unresolved reference: MyException2.

如何在Kotlin上同时捕获许多例外?

kotlin

58
推荐指数
2
解决办法
1万
查看次数

如何在Kotlin中使用挥发性物质

我试过这样的事情:

private volatile var instanceState: InstanceState = InstanceState.starts

Error:  'Expected member declaration'
Run Code Online (Sandbox Code Playgroud)

和这样:

private volatile var instanceState: InstanceState = InstanceState.starts

Error:  'Property getter or setter expected'
Run Code Online (Sandbox Code Playgroud)

Kotlin不支持易失性?

kotlin

10
推荐指数
1
解决办法
4587
查看次数

对象构造函数和Delegates.notNull

object WalletConfig {

    init {
        fill(HashMap<String, String>())
    }

    var clientUrl: String by Delegates.notNull()
        private set

    fun fill(settingMap: Map<String, String>) {
        try {
            clientUrl = settingMap["URL_CLIENT"] ?: ""
        } catch(ex:Exception) { }
    }
}
Run Code Online (Sandbox Code Playgroud)

throw ex:fill:在ru.WalletConfig.setClientUrl(WalletConfig.kt)加载'wallet.config'配置文件:java.lang.NullPointerException

kotlin

2
推荐指数
1
解决办法
490
查看次数

如何在Kotlin中初始化注释的数组属性

@Entity
@Table(name = "t_payment")
data class PaymentEntity(
        @ManyToOne(cascade = CascadeType.DETACH)
        @JoinColumn(name = "user_id", nullable = false)
        var user: User? = null) : Serializable {
}
Run Code Online (Sandbox Code Playgroud)

由于编译错误: "Type mismatch"

kotlin

1
推荐指数
1
解决办法
313
查看次数

标签 统计

kotlin ×4