1

I'm working on a java lib in scala.

I got something like this:

def myFunc(): Thing[Iterable[T]] = {
  // call java lib for the result
  ...
  javaResult  // Problem: it's Thing[java.lang.Iterable[T]]
}

So you see the problem is that the return type of the java thing is Thing[java.lang.Iterable[T]]. I've tried importing scala.collection.JavaConverters._ but that doesn't work. Note that I don't have access to the java lib and I'm not able to extract that iterable then reconstruct a Thing object with a scala one.

I can annotate the return type as java.lang.Iterable but as scala and java are designed to be work together, I'm wondering if there's some way to solve this problem elegantly?

Alex K
  • 8,269
  • 9
  • 39
  • 57
darkjh
  • 2,821
  • 7
  • 35
  • 43

1 Answers1

0

"Designed to work together" means exactly that you can return Thing[java.lang.Iterable[T]]. It does look like it is your only option.

Dima
  • 39,570
  • 6
  • 44
  • 70