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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:13+00:00 2026-05-28T22:08:13+00:00

If I evaluate the following expression in Scala REPL: scala> 1 + 1 res0:

  • 0

If I evaluate the following expression in Scala REPL:

scala> "1" + 1
res0: java.lang.String = 11

the returned type is: java.lang.String.

If I evaluate this similar expression:

scala> 1 + "1"
res1: String = 11

the returned type is: String.

Why the difference?

  • 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-28T22:08:13+00:00Added an answer on May 28, 2026 at 10:08 pm

    There is no difference, however it is also not a bug. In this case:

    "1" + 1
    

    you are using built-in feature of Java to concatenate anything into a String. After all, many people convert numbers to strings using the following “idiom”:

    String s = "" + 5;
    

    It works in Scala as well and results with java.lang.String – same as in Java.

    On the other hand:

    1 + "1"
    

    is a bit more complex. This is translated into:

    1.+("1")
    

    and the +() method is taken from Int.+ method located in Int.scala:

    final class Int extends AnyVal {
        //....
        def +(x: String): String = sys.error("stub")
    

    The String in this context is defined in Predef.scala:

    type String        = java.lang.String
    

    which is the source of the type “difference“. As you can see both strings are in fact the same type.

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

Sidebar

Related Questions

The following code fails in 'Evaluate' with: This expression was expected to have type
I'd like to disable truncation of string values in the Scala REPL. The following
How do i Evaluate the following expression from a string to a answer as
What is the best was to evaluate an expression like the following: (A And
The following code: var constant = Expression.Constant(find me, typeof(string)); // memberExpression evaluates to a
I'm trying to evaluate a test string against a regular expression I build from
How does Python evaluate the following expression? anim1 gets executed after anim2 . How
The following xpath does not seem to work: //FullName[sum(string-length(FirstName) | string-length(LastName))>= 30] Error: Expression
In objective-c I am trying to evaluate the following expression: _c = _f /
Is there a way to make the following code behind expression to evaluate to

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.