Using Scala array from java

I am trying to use some library code written in scala from a java program. I have a function that returns an array (a scala Array), and I thought what could be done

Tree[] = ScalaObject.myScalaFunction() 

But I get this error:

 [error] found : scala.runtime.BoxedArray [error] required: org.grammaticalframework.Trees.Absyn.Tree[] 

What is the correct way to use scala array in java?

+4
source share
1 answer

With 2.7, you should be able to

 Tree[] t = (Tree)ScalaObject.myScalaFunction().unbox(Tree.class); 

in java.

From 2.8, it will work as you hoped.

+10
source

Source: https://habr.com/ru/post/1311733/


All Articles