作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下类,但在将 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/
我是一名优秀的程序员,十分优秀!