java - 如何在kotlin中替换::new?

标签 java kotlin

按照 Java 中的 Disruptor 教程,他们进行了以下调用

Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor);

哪里LongEvent使用无参数的默认构造函数实例化 - 即。 new LongEvent() .

Kotlin 中的等效行在 ::new 处抛出错误。 。 ::new 的正确语法是什么在 Kotlin 中?

# THIS IS INVALID
val disruptor = Disruptor<LongEvent>(LongEvent::new, bufferSize, executor)

最佳答案

constructor reference expression在 kotlin 中是 ::LongEvent

Constructors can be referenced just like methods and properties. Constructors are referenced by using the :: operator and adding the class name.

关于java - 如何在kotlin中替换::new?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44851530/

相关文章:

java - 如何用jUnit声明数据库列的Grails Controller 更新?

java - JKS 文件上的 SQL Server 2019 外部脚本执行身份验证错误

java - 如何使用 apache Camel 根据正文内容进行 GET api 调用

java - 如何从数组中删除对象

android - Recyclerview View 未填充

java - NOOP 在 JOOQ 哪里

Kotlin:如何展平 HashMap 列表

java - Android Studio写文件时渲染问题

inheritance - Kotlin 覆盖成员集并获取

java - 如何使用 EasyMock 测试返回另一个方法的方法?