I would like to call the following java method from scala:
protected final FilterKeyBindingBuilder filter(String urlPattern, String... morePatterns) {
return filtersModuleBuilder.filter(Lists.newArrayList(urlPattern, morePatterns));
}
my scala caller looks like this
def test(url: String, urls: String*) {
filter(url, urls: _*).through(classOf[MyTestWhateverFilter])
}
this compiles, however, executing the code gives an exception:
java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to [Ljava.lang.String;
I also tried this:
def test(url: String, urls: String*) {
filter(url, urls.map(_.asInstanceOf[java.lang.String]) :_*).through(classOf[MyTestWhateverFilter])
}
in this case the exception was:
java.lang.ClassCastException: scala.collection.mutable.ArrayBuffer cannot be cast to [Ljava.lang.String;
I thought that in 2.8 Array[String] is passed to java as String[] array and no extra unboxing is necessary.
Any ideas?
Thanks in advance!
EDIT:
how to replicate it:
import com.google.inject.servlet.ServletModule
trait ScalaServletModule extends ServletModule{
def test(s: String,strs: String*) = {
println(strs.getClass)
println(super.filter(s,strs:_*))
}
}
object Test {
def main(args: Array[String]) {
val module = new ServletModule with ScalaServletModule
module.test("/rest")
}
}
/opt/local/lib/scala28/bin/scala -cp /Users/p.user/Downloads/guice-2.0/guice-2.0.jar:/Users/p.user/Downloads/guice-2.0/guice-servlet-2.0.jar:/Users/p.user/Downloads/guice-2.0/aopalliance.jar:/Users/p.user/Downloads/javax.jar/javax.jar:. Test
result:
class scala.collection.mutable.WrappedArray$ofRef
java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to [Ljava.lang.String;
at ScalaServletModule$class.test(test.scala:6)
at Test$$anon$1.test(test.scala:11)
at Test$.main(test.scala:12)
at Test.main(test.scala)