0

I need to pass a 2-dimensional Java array of primitive values defined as

int myArray[][] = {{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }};

in Java terms into a Java library function from a Scala application.

How to define such an object in Scala?

Ivan
  • 63,011
  • 101
  • 250
  • 382

1 Answers1

5

The equivalent Scala to your Java is:

val myArray = Array(Array(1, 2), Array(3, 4), Array(5, 6), Array(7, 8))

Scala uses the exact same Array that Java does. An Array in Scala appears to have additional functionality because arrays are implicitly wrapped by WrappedArray.

For much more, see this answer.

Community
  • 1
  • 1
Leif Wickland
  • 3,693
  • 26
  • 43
  • I couldn't believe this (sending Scala array of Scala objects to Java instead of Java array of primitive values) would work! But seems working :-) – Ivan Mar 23 '12 at 00:21
  • 1
    @Ivan: currently, there are no such things as Scala Arrays ! Scala uses just Java arrays. Extra methods are added through implicit conversions. – paradigmatic Mar 23 '12 at 08:04