kotlin - 下面 kotlin 代码中第一行的含义是什么。从 Java 到 Kotlin 的 Newbee
问题描述
我是一名 Java 程序员,也是 Kotlin 的新手。请帮助我理解下面的代码,尤其是第一行。
class SiteListEventBus : EventBus<SiteListEventBus.SiteListChangeEvent, String, NotificationHandler<SiteListEventBus.SiteListChangeEvent>>() {
data class SiteListChangeEvent(val entityId: String, val routingKey: String)
override fun getSubscriptionKey(event: SiteListChangeEvent?): String {
return event!!.routingKey
}
}
解决方案
这是我阅读第一行的方式:
class SiteListEventBus
定义一个新类。: FooBar()
FooBar
使用空构造函数扩展类。FooBar
实际上EventBus<SiteListEventBus.SiteListChangeEvent, String, NotificationHandler<SiteListEventBus.SiteListChangeEvent>>
,泛型在这里的应用方式与您在 Java 中所期望的方式相同。class SiteListEventBus : FooBar() {
开始实现SiteListEventBus
类。
以下是我阅读其余部分的方式:
data class SiteListChangeEvent(val entityId: String, val routingKey: String)
创建一个data class
.override fun getSubscriptionKey
与注解override
类似。@Override
覆盖方法getSubscriptionKey
。event!!.routingKey
该event
变量可以为空。我建议阅读有关!!
operator的内容。
推荐阅读
- java - 猜谜游戏中的while循环有问题吗?
- php - Google OAuth 2 回调网址
- elasticsearch - 如何根据另一个字段计算数据字段的唯一交集?
- gis - OSMnx:取消链接隧道和桥梁
- excel - 如何编写代码以根据单元格值将数据拆分为多个工作簿
- android - 从 RxJava 嵌套链中的 LiveDataReactiveStreams.fromPublisher() 发布多个结果
- python - 如果 Python GTK 中的内容发生变化,则滚动到 Scrollable 的底部
- java - JSON解析错误:空;嵌套异常是 com.alibaba.fastjson.JSONException
- php - 在验证 Woocommerce 的计费字段后,如何运行代码?
- java - 我不太确定如何在自由配置文件中配置 db2drivers