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 8293497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:50:49+00:00 2026-06-08T13:50:49+00:00

I’m using asynchttpclient. When building up parameters, one passes a java.util.Map to the setParameters

  • 0

I’m using asynchttpclient. When building up parameters, one passes a java.util.Map to the setParameters method.

The (Java) signature looks like the following:

setParameters(Map<String,Collection<String>);

Real day 1 stuff. But wow, I’m trying to call it from Scala and I cannot for the life of me create a collection to match that signature.

Here’s the mess I’ve created so far.

var m:java.util.Map[java.lang.String,java.util.Collection[java.lang.String]] = new java.util.HashMap[java.lang.String,java.util.HashSet[java.lang.String]]()
val req = new RequestBuilder().setUrl("http://localhost:1234/").setParameters(m).build

And here’s the error message,

Multiple markers at this line
- type mismatch; found : java.util.HashMap[java.lang.String,java.util.HashSet[java.lang.String]] required: 
 java.util.Map[java.lang.String,java.util.Collection[java.lang.String]] Note: java.util.HashSet[java.lang.String] <: java.util.Collection[java.lang.String], but Java-defined 
 **trait Map is invariant in type V. You may wish to investigate a wildcard type such as `_ <: java.util.Collection[java.lang.String]`. (SLS 3.2.10)**
- type mismatch; found : 

Fair enough, I wouldn’t have thought I was doing something particularly complicated, but lets give the compiler suggestion a try…

So I change it to the following

 var m:java.util.Map[java.lang.String,_ <: java.util.Collection[java.lang.String]] = new java.util.HashMap[java.lang.String,java.util.HashSet[java.lang.String]]()
 val req = new RequestBuilder().setUrl("http://localhost:1234/").setParameters(m).build

And receive the following lovely error message in response.

Multiple markers at this line
    - overloaded method value setParameters with alternatives: (com.ning.http.client.FluentStringsMap)com.ning.http.client.RequestBuilder <and> 
     (java.util.Map[java.lang.String,java.util.Collection[java.lang.String]])com.ning.http.client.RequestBuilder cannot be applied to (java.util.Map[java.lang.String,_$1])

Back to basic’s, I’d also like to mention that my first attempt was as follows.

   import scala.collection.JavaConverters._
   var m = Map[String,Set[String]]()
   val req = new RequestBuilder().setUrl("http://localhost:1234/").setParameters(m.asJava).build

But that produced the following

Multiple markers at this line
– overloaded method value setParameters with alternatives: (com.ning.http.client.FluentStringsMap)com.ning.http.client.RequestBuilder
(java.util.Map[java.lang.String,java.util.Collection[java.lang.String]])com.ning.http.client.RequestBuilder cannot be applied to (java.util.Map[String,Set[String]])

Edit, thanks to __0, this is now working. Here’s my final code:

 def buildReqMap(in: Map[String, String]) = {
   import java.util.{ Map => JMap, Collection => JColl, HashMap => JHashM, HashSet => JHashS }
   val m: JMap[String, JColl[String]] =
     new JHashM[String, JColl[String]]()
   in.fold(m) { (a, b) =>
     {
       val s = new JHashS[String]()
       s.add(b.asInstanceOf[String])
       m.put(a.asInstanceOf[String], s)
       m
     }
   }
   m
 }

 def main(args: Array[String]): Unit = {
   val m = buildReqMap(
     Map(
       ("delimited" -> "length"),
       ("track" -> "binarytemple,music,kittens")))

   val req = new RequestBuilder().setUrl("http://localhost:1234/").setParameters(m).build
   val fut = asyncHttpClient.executeRequest(req, handler).get
  • 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-06-08T13:50:50+00:00Added an answer on June 8, 2026 at 1:50 pm

    Well, the first error message made it clear— since java.util.Map is mutable, it can’t handle variance. So you cannot cast a Map[_,Set[_]] to a Map[_,Collection[_]].

    val m: java.util.Map[String, java.util.Collection[String]] = 
       new java.util.HashMap[String,java.util.Collection[String]]()
    val s = new java.util.HashSet[String]()
    s.add("welt")
    m.put("hallo", s)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

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.