按照 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/