2
votes

I'm working with the following class and have trouble converting a scala long list to 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
    }
  }

I'm getting the error:

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

How can I do the conversion properly?

1
List[java.lang.Long](545543434).asJava would be the simplest way, I think. Too short for an answer :)Vladimir Matveev
Thanks a lot! Still getting to grips with the language. :)orestisf

1 Answers

1
votes

Right now you are converting scala List[..] into java equivalent with asJava method call. What you need to do is to convert the elements themselves. To do that you can simply map all the elements with longToLong eg.

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