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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:16:03+00:00 2026-06-10T14:16:03+00:00

Cutting right to the chase Convert int to String implicit def int2string(i: Int): String

  • 0

Cutting right to the chase

“Convert” int to String

 implicit def int2string(i: Int): String = {
    "foo"
  }

Method that takes a String and prints

def printString(i: String) = print(i)

Calling printString with an Int argument

printString(_:Int)

Shouldn’t that display “foo”? However printString(i:String) never gets called.

printString(1) prints “foo”

Is there a problem here or I’m missing something?

  • 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-10T14:16:05+00:00Added an answer on June 10, 2026 at 2:16 pm

    That’s because what printString(_:Int) actually what it does is to turn that expression in a function that takes a Int and probably is never invoked… See:

    scala> implicit def int2string(i: Int): String = "foo"
    int2string: (i: Int)String
    
    scala> def printString(i: String) = print(i)
    printString: (i: String)Unit
    

    No syntax error here mean it is working. As an illustration:

    scala> printString(_:Int)       // Function from Int to Unit 
    res0: Int => Unit = <function1>  
    

    The compiler turns the outer expression into { x:Int => printString(x) }, and then applies the implicit conversion since the implicit is in scope, so the outcome is { x:Int => printString(int2string(x)) }.

    A non-working one, since there is no conversion from Object to String:

    scala> printString(_:Object)
    <console>:10: error: type mismatch;
     found   : java.lang.Object
     required: String
                  printString(_:Object)
    

    Now to actually see the printing we need to invoke it:

    scala> val foo = printString(_:Int)
    foo: Int => Unit = <function1>
    
    scala> foo(5)
    foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I'd like to say that I'm already looking into the Cutting Stock
I appreciate that Security is seen as a cross-cutting concern and in my current
Hey so i'm trying to make a function that takes in an image refrence
We are working with some new Cutting Tools that can have it's hardware parameters
I am having trouble cutting down my string. I have a windows form application
I am cutting and joining a video file using mencoder. But the output file
I found this post on Crystal Reports Cutting Off Text in PDF , but
I try to repeat and learn more advanced uses and options when cutting trees
is it possible to transfer files using vb.net? Cutting the files from a certain
How can I plot a dendrogram right on top of a matrix of values,

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.