2

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?

2
  • 3
    List[java.lang.Long](545543434).asJava would be the simplest way, I think. Too short for an answer :) Commented May 9, 2019 at 21:06
  • Thanks a lot! Still getting to grips with the language. :) Commented May 9, 2019 at 21:13

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.