0

How does following code work in Akka:

@Override
public Receive createReceive() {
    return receiveBuilder()
            .match(DeviceManager.RequestTrackDevice.class, this::onTrackDevice)
            .match(RequestDeviceList.class, this::onDeviceList)
            .match(Terminated.class, this::onTerminated)
            .build();
}

onTrackDevice is another method in same class and it takes an input. Here it is invoked without any argument. I understand that passed message would be passed to onTrackDevice too.

But how does it all fit in java syntax?

Mandroid
  • 6,200
  • 12
  • 64
  • 134

1 Answers1

0

For most language which support lambda, it could support eta-conversion.

E.g.

x => Math.abs(x) is a lambda, it could be shorted as Math.abs

Java8 also support it, but it did not use Math.abs, it use Math::abs.

So, here this::onDeviceList is just a lambda (it just be supported from java8).

When the actor receive the variable msg with the type RequestDeviceList, it will call this::onDeviceList(msg) internal. Here, as this::onDeviceList is a lambda, so actor can directly call this lambada and set parameter('msg') when call this lambda function (lambda as function parameter, so you did not see parameter here)

In a word, you need to be familiar with java8's lambda support to know how it fits in java syntax.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
atline
  • 28,355
  • 16
  • 77
  • 113