Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Scala array from java

Tags:

scala

I'm 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 it would be possible to do

Tree[] = ScalaObject.myScalaFunction()

But the I get this error :

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

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

like image 329
Grégoire Avatar asked Dec 29 '22 15:12

Grégoire


1 Answers

With 2.7, you should be able to

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

in Java.

With 2.8, it will work as you hoped it would.

like image 113
Rex Kerr Avatar answered Feb 13 '23 02:02

Rex Kerr