[英]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.