gpt4 book ai didi

java - 错误 - ReceiveBuilder 中的构建方法编译错误,无法解析类型 scala.Product

转载 作者:行者123 更新时间:2023-11-30 06:13:48 28 4
gpt4 key购买 nike

我是 Akka-Actor 的新手。

尝试运行简单的 akka-actor 程序来理解 akka-actor。

我无法解决两个编译错误。

The method build() from the type AbstractPFBuilder<Object,BoxedUnit> refers to the missing type PartialFunction

The type scala.Product cannot be resolved. It is indirectly referenced from required .class files. 

Compilation error at Props props() method.

下面是实际代码。

AkkaActor 程序:

package com.abcplusd.akka;

import akka.actor.AbstractLoggingActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.japi.pf.ReceiveBuilder;

public class AkkaStarted {

static class Counter extends AbstractLoggingActor {
static class Message {}
private int count = 0;

{
receive(ReceiveBuilder
.match(Message.class, this::onMessage)
.build()
);
}

private void onMessage(Message message) {
count ++;
System.out.println("Increased Counter: " + count);
}
public static Props props() {
return Props.create(Counter.class);
}

}
public static void main (String[] args) {
ActorSystem system = ActorSystem.create("Sample1");
final ActorRef counter = system.actorOf(Counter.props(), "Counter");
counter.tell(new Counter.Message(), ActorRef.noSender());
System.out.println("Enter to Terminate");
}

}

AkkaActor 版本 2.4.9。

位于我的 pom.xml 设置下方。

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<akka.version>2.4.9</akka.version>
</properties>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.4</version>
</dependency>
</dependencies>

最佳答案

通过更改 scala-lang 版本解决了编译问题。

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>

关于java - 错误 - ReceiveBuilder 中的构建方法编译错误,无法解析类型 scala.Product,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49666029/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com