So I'm playing with writing a battlecode player in Scala. In battlecode certain classes are disallowed and there is a runtime exception if you ever try to access them. When I use the Array.fill function I get a message from the battlecode server saying [java] Illegal class: scala/reflect/Manifest$
. This is the offending line:
val g_score = Array.fill[Int](rc.getMapWidth(), rc.getMapHeight())(0)
The method takes an implicit ClassManifest
argument which has the following documentation:
A ClassManifest[T] is an opaque descriptor for type T. It is used by the compiler
to preserve information necessary for instantiating Arrays in those cases where
the element type is unknown at compile time.
But I do know the type of the array elements at compile time, as shown above I explicitly state that they will be Int
. Is there a way to avoid this? To workaround I've written my own version of Array.fill
. This seems like a hack. As an aside, does Scala have real 2D arrays? Array.fill
seems to return an Array[Array[T]]
which is the only way I found to write my own. This also seems inelegant.
Edit: Using Scala 2.9.1