在 android kotlin 中访问 sealed class 的嵌套级别

Accessing the nested level of sealed class in android kotlin

我有封印class

MyEvents.kt

sealed class MyEvents<out T : Any>{
    sealed class HelloBroadcasting<out T : Any> : MyEvents<Nothing>() {
        sealed class FeatureSegments : HelloBroadcasting<Nothing>() {
            class SegmentationCourseSeekChapterChange(val context: Context) : FeatureSegments()
            class SegmentationChapterNameClicked(val context: Context, chapterName: String) : FeatureSegments()
            class SegmentationChapterSelectionFromChapterList(val context: Context) : FeatureSegments()
        }
    }
}

我叫封号class

sendTheEventEvent(MyEvents.HelloBroadcasting.FeatureSegments.SegmentationChapterNameClicked(mContext,it.textDirection.toString()))

我正在尝试将事件接收为

fun sendCleverTapEvent(event: MyEvents<Int>) {
        when(event){
            is MyEvents.HelloBroadcasting.FeatureSegments.SegmentationChapterNameClicked -> test(event.context,event.) // ---> Here I am not able to access the name
            is MyEvents.HelloBroadcasting.FeatureSegments.SegmentationChapterSelectionFromChapterList -> TODO()
            is MyEvents.HelloBroadcasting.FeatureSegments.SegmentationCourseSeekChapterChange -> TODO()
        }
    }

我无法访问接收部分的名称。当嵌套级别存在时如何正确执行此操作?

你必须让 chapterName 变成 属性:

- chapterName: String
+ val chapterName: String