1

我有一个密封类

我的事件.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()
        }
    }
}

我叫密封类

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()
        }
    }

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

4

1 回答 1

1

您必须创建chapterName一个属性:

- chapterName: String
+ val chapterName: String
于 2021-11-23T15:26:35.027 回答