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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:41:14+00:00 2026-05-26T17:41:14+00:00

Possible Duplicate: How can I chain implicits in Scala? Can Scala apply multiple implicit

  • 0

Possible Duplicate:
How can I chain implicits in Scala?

Can Scala apply multiple implicit conversions in one expression?

Consider this simple example:

  case class Wrapper(s: String)

  case class WrapperWrapper(w: Wrapper)

  implicit def string2Wrapper(s: String) = Wrapper(s)

  implicit def wrapper2WrapperWrapper(w: Wrapper) = WrapperWrapper(w)

  // implicit conversation -->  w = string2Wrapper("w")
  val w: Wrapper = "w"

  // implicit conversation -->  ww = wrapper2WrapperWrapper(w)
  val ww: WrapperWrapper = w

  // does NOT compile!
  // ideally --> sad = wrapper2WrapperWrapper(string2Wrapper("ww"))
  val sad: WrapperWrapper = "ww"

Is there any way to get the “double” conversion in the last line to work?

I can help things along by defining another implicit like:

implicit def string2WrapperWrapper(s:String) = wrapper2WrapperWrapper(s)

but it seems like that shouldn’t be necessary…

  • 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-26T17:41:15+00:00Added an answer on May 26, 2026 at 5:41 pm

    I’m afraid I don’t have a concise reference to hand (the answer is scattered through 6.26 and chapter 7 of The Scala Language Specification), but the answer is no.

    This is due to practicality – double implicit conversions would square the number of possible conversions available, greatly increasing the chance of collisions and making it harder to work out exactly what would happen with a given conversion.

    It’s not ideal that you have to declare the String to WrapperWrapper conversion yourself; but given how rarely you need to do this in practice, compared to the potential confusion of double implicits, I do consider it the lesser of two evils.

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

Sidebar

Related Questions

Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? How do you filter on
Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? Does it possible to get
Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
Possible Duplicate: Can select * usage ever be justified? Curious to hear this from
Possible Duplicate: Can a JavaScript object have a prototype chain, but also be a
Possible Duplicate: Can somebody explain this Javascript method ? (x = [].reverse)() === window
Possible Duplicate: Can someone explain this template code that gives me the size of
Possible Duplicate: Can you add multiple jars in a jar file and then launch
Possible Duplicate: Can a JavaScript function return itself? Consider the following javascript function: var

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.