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

  • Home
  • SEARCH
  • 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 6585253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:38:19+00:00 2026-05-25T16:38:19+00:00

Given the following Scala code: def stream(callback: (String, Array[Byte]) => Unit) { callback(application/json;charset=utf-8, Array(1))

  • 0

Given the following Scala code:

def stream(callback: (String, Array[Byte]) => Unit) {
    callback("application/json;charset=utf-8", Array(1))
    callback("application/xml;charset=utf-8", Array(1))
}

@Test
def whenStreaming_thenShouldSeeSameMessages() {
    var actualMessages = List.empty[(String, Array[Byte])]
    sut.stream {
        (contentType, payload) =>
            actualMessages += (contentType, payload)
    }

    expect(List("application/json;charset=utf-8", "application/xml;charset=utf-8")) {
        actualMessages
    }
}

Why am I getting the following error message:

error: too many arguments for method +: (other: String)java.lang.String
actualMessages += (contentType, payload)

Specifically, payload is highlighted in IDEA, and on the command line, += is highlighted. I really don’t understand that error message.

  • 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-25T16:38:20+00:00Added an answer on May 25, 2026 at 4:38 pm

    The method to create a new list with an appended element is actually :+. To update the list var with an appended version, you need to do,

    actualMessages :+= (contentType, payload)
    

    Or you can prepend with,

    actualMessages +:= (contentType, payload)
    // or, equivalently,
    // actualMessages ::= (contentType, payload)
    

    (For big lists, prepending is actually preferable, as it’s O(1) compared to O(n) for appending. One strategy is to use prepending to build the list in reverse, and then at the end call List.reverse.)

    With the + operator you’re trying to use, Scala thinks you want to do string concatenation,

    scala> List("hello") + " world"
    res0: java.lang.String = List(hello) world
    

    This is an unfortunate carry-over from Java. Generic string concatenation is implemented in Scala using an implicit conversion defined in scala.Predef,

    implicit def any2stringadd (x: Any): StringAdd 
    

    What’s happening is that List does not implement a + method, so the compiler looks for a conversion to something that does provide +, and finds any2stringadd. This is how, e.g., true + " false" works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Scala code (e.g., in REPL) object A{def foo:Unit = {}} object
Given the following code: class A extends Actor { def act() { loop {
For the following code: package FileOperations import java.net.URL object FileOperations { def processWindowsPath(p: String):
Consider the following code: abstract class X { def a:Unit a } class Y
Given the following code: case class ChangeSet(field:String, from:Object, to:Object) private var changed:List[ChangeSet] = Nil
Given the following code: abstract class Field { type T val data: List[T] def
Consider the following Scala code: package scala_java object MyScala { def setFunc(func: Int =>
Given following Ruby statements: (Read input and store each word in array removing spaces
Given the following code (that doesn't work): while True: # Snip: print out current
I am generating the scala AST using the following code: val setting = new

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.