private var adapter: MsgAdapter? = null

👇
private lateinit var adapter: MsgAdapter

判断是否已经初始化完成:
if (!::adapter.isInitialized) {
   adapter = MsgAdapter(msgList)
}
interface Result {
    class Success(val msg: String) : Result
    class Failure(val error: Exception) : Result

    fun getResultMsg(result: Result) = when (result) {
        is Success -> result.msg
        is Failure -> result.error.message
        else -> throw IllegalArgumentException()
    }
}

采用密封类优化👇
sealed class Result
class Success(val msg: String) : Result()
class Failure(val error: Exception) : Result()

fun getResultMsg(result: Result) = when (result) {
    is Success -> result.msg
    is Failure -> result.error.message
		//这里去掉了那个没有必要的else
}
密封类及其所有子类只能定义在同一个文件的顶层位置,不能嵌套在其他类中,
这是被密封类底层的实现机制所限制的。