代码之家  ›  专栏  ›  技术社区  ›  Devrath

访问android kotlin中密封类中的嵌套级别

  •  1
  • Devrath  · 技术社区  · 3 年前

    我有一节密封课

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

    我称之为密封类

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

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

    1 回复  |  直到 3 年前
        1
  •  1
  •   Marvin    3 年前

    你必须 chapterName 一处房产:

    - chapterName: String
    + val chapterName: String