How to overload bang(!) operator in Scala Actor model?

后端 未结 3 1908
终归单人心
终归单人心 2021-01-20 02:56

In an Actor model implementation in Scala, can we override the bang(!) operator. Can we modify the operation of message passing by overloading this operator?

Example

3条回答
  •  无人及你
    2021-01-20 03:45

    You can try the following code.

    override def !(msg:Any):Unit =
    {
       //logic for writing to logs..
       super.!(msg)
    }
    

    This works fine. However, i want to differentiate behavior of !, depending upon the messages I am sending. for example below:

    actor_name!(arg1,arg2,arg3)
    actor_name1!(arg4, arg5)
    

    How do i differentiate between these two message sending notation in the overriding code?

提交回复
热议问题