Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:17:02+00:00 2026-05-17T15:17:02+00:00

I would like to call the following java method from scala: protected final FilterKeyBindingBuilder

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:17:02+00:00Added an answer on May 17, 2026 at 3:17 pm

    I’ve just tried to reproduce your error using Scala 2.8.0 and can’t. Here’s my code

    // Example.java
    public class Example {
      public static void test(String... args) {
        System.out.println(args.getClass());
      }
    }
    
    // In test.scala
    object Test {
      def main(args: Array[String]) {
          test("1", "2", "3")
      }
      def test(strs: String*) = {
        println(strs.getClass)
        Example.test(strs:_*)
      }
    }
    

    I get the following output:

    class scala.collection.mutable.WrappedArray$ofRef
    class [Ljava.lang.String;
    

    So it looks like the compiler is inserting the correct conversion to convert the WrappedArray.ofRef to a String[].

    Edit

    Just tried running your example. It looks like some interaction of super-accessors in traits with converting Scala varargs to Java varargs. If you change the trait to a class it works.

    From the decompiled output of ScalaServletModule$class, it looks like it doesn’t do the necessary conversion from String* to String[] when calling the super accessor (line 19).

    public static void test(ScalaServletModule, java.lang.String, scala.collection.Seq);
      Code:
       0:   getstatic   #11; //Field scala/Predef$.MODULE$:Lscala/Predef$;
       3:   aload_2
       4:   invokevirtual   #18; //Method java/lang/Object.getClass:()Ljava/lang/Class;
       7:   invokevirtual   #22; //Method scala/Predef$.println:(Ljava/lang/Object;)V
       10:  getstatic   #11; //Field scala/Predef$.MODULE$:Lscala/Predef$;
       13:  aload_0
       14:  aload_1
       15:  aload_2
       16:  checkcast   #24; //class "[Ljava/lang/String;"
       19:  invokeinterface #30,  3; //InterfaceMethod ScalaServletModule.ScalaServletModule$$super$filter:(Ljava/lang/String;[Ljava/lang/String;)Lcom/google/inject/servlet/ServletModule$FilterKeyBindingBuilder;
       24:  invokevirtual   #22; //Method scala/Predef$.println:(Ljava/lang/Object;)V
       27:  return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to do the following. Basically have a stored procedure call another
I would like to call python script files from my c++ program. I am
I would like to call Perl script files from my c++ program. I am
I would like to call my unmanaged C++ libraries from my C# code. What
From my bash shell I would like to call a program n times with
I would like to call C# service with using PHP, anyone know how to
I would like to call FindLast on a collection which implements IEnumerable , but
I would like to call a windows program within my code with parameters determined
I have a controller action which I would like to call another controller action.
I have a Silverlight application in which I would like to call a WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.