0

Following a tutorial on Disruptor in Java and they make the following call

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

Where LongEvent is instantiated using a default constructor of no argument- ie. new LongEvent().

The equivalent line in Kotlin is throwing an error at the ::new. What is the correct syntax for ::new in Kotlin?

# THIS IS INVALID
val disruptor = Disruptor<LongEvent>(LongEvent::new, bufferSize, executor)
Adam Hughes
  • 14,601
  • 12
  • 83
  • 122

1 Answers1

5

the constructor reference expression in kotlin is ::LongEvent.

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

holi-java
  • 29,655
  • 7
  • 72
  • 83