1

In my java code I am using a method, let's call foo(), that returns a scala.Double[].

scala.Double[] arr = foo();

I want to sum up arr into a scala.Double, but am having trouble. I've found that doing any kind of math operation on scala.Doubles gets me an error message from my IDE:

arr[0] + arr[1];
arr[0] * arr[1];
//etc

get me messages like

Operator '+' cannot be applied to 'scala.Double', 'scala.Double'

How can I do math operations on scala.Doubles within java code? (alternatively, is there another way to sum up a scala.Double[] within java code?)

0

1 Answer 1

0

It's not clear how you got scala.Double[] in Java. If you have Array[Double] in Scala, it's seen in Java as double[], not scala.Double[].

Anyway, if you have scala.Double[] in Java

public class App {
  public static scala.Double[] arr = foo();
}

then it's seen in Scala also as Array[scala.Double]

object App1 {
  val arr1: Array[Double] = App.arr
}

and then the latter is seen back in Java as double[]

public class App {
  public static scala.Double[] arr = foo();
  public static double[] arr2 = App1.arr1();
}

Then you can do arr2[0] + arr2[1], arr2[0] * arr2[1]...

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.