gpt4 book ai didi

java - 如何将 java.util.List[java.lang.Long] 转换为 java.util.List[Long]

转载 作者:行者123 更新时间:2023-11-30 05:39:00 25 4
gpt4 key购买 nike

我正在使用以下类,但在将 scala 长列表转换为 java.util.List[Long] 时遇到问题:

import scala.collection.JavaConverters._
import org.apache.flink.streaming.connectors.twitter.TwitterSource

class myFilterEndpoint2 extends TwitterSource.EndpointInitializer with Serializable {
override def createEndpoint(): StreamingEndpoint = {
val customEndpoint2 = new StatusesFilterEndpoint()
customEndpoint2.followings(List[Long](545543434).asJava)
return customEndpoint2
}
}

我收到错误:

Type mismatch, expected: java.util.List[java.lang.Long], actual: java.util.List[Long]

如何正确进行转换?

最佳答案

现在,您正在使用 asJava 方法调用将 scala List[..] 转换为等效的 java。您需要做的是转换元素本身。为此,您可以简单地使用 longToLong 映射所有元素,例如。

customEndpoint2.followings(List[Long](545543434L).map(long2Long).asJava)

关于java - 如何将 java.util.List[java.lang.Long] 转换为 java.util.List[Long],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56067537/

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