在android kotlin中訪問密封類的嵌套級別

德夫拉特

我有一個密封的班級

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

我無法訪問接收部分中的名稱。當嵌套級別存在時如何正確執行此操作?

馬文

您必須創建chapterName一個屬性:

- chapterName: String
+ val chapterName: String

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章