[英]What kind the implementation it is?
On the akka website , you can the following definition: 在akka网站上 ,您可以定义以下内容:
sealed trait AccountCommand[Reply] extends ExpectingReply[Reply]
final case class Withdraw(amount: BigDecimal)(override val replyTo: ActorRef[OperationResult])
extends AccountCommand[OperationResult]
How to assign an ActorRef
to replyTo
? 如何分配
ActorRef
来replyTo
?
I've taken the code as an example and try to implement on own type: 我以代码为例,尝试实现自己的类型:
case object Channel (override val replyTo: ActorRef[SendMessage])
extends ExpectingReply[SendMessage]
and the compiler complains. 编译器抱怨。
The way, that the compiler does not complain: 这样,编译器不会抱怨:
case object Channel extends ExpectingReply[SendMessage] {
override def replyTo: ActorRef[SendMessage] = ???
}
Is the example on akka website wrong? akka网站上的示例是否错误?
If your message does not have fields, you can use a case class
without parameters: 如果您的消息没有字段,则可以使用不带参数的
case class
:
case class Channel()(override val replyTo: ActorRef[SendMessage])
extends ExpectingReply[SendMessage]
If you're asking about how to create an instance of such a class, then you should use the standard multi-parameter function call syntax: 如果您询问如何创建此类的实例,则应使用标准的多参数函数调用语法:
val msg = Channel()(sendMessageActorRef)
That being said, it looks to me that specifically in that part of the Akka API that you linked to, you don't have to explicitly provide any ActorRef
s, Effect
s seem to do it kind of automatically. 话虽这么说,它看起来对我来说,特别是在你链接到阿卡API的一部分,你没有明确提供任何
ActorRef
S, Effect
小号似乎有种自动做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.