[英]Accessing the nested level in sealed class in android kotlin
我有一個密封的 class
我的事件.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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.