在 Kotlin 中,标题和正文都是可选的;如果类没有主体,可以省略花括号。
所以我们可以定义类,
class Empty
这种类有什么用?
最佳答案
您可以将它用于一些自定义异常:
class Empty : Exception()
或作为 marker interface :
interface Empty
或作为 data class :
data class Empty(val s: String)
或作为 marker annotation :
annotation class Empty
~ 这很好post阅读。
关于Kotlin - 没有 body 的类有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801587/