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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:45:01+00:00 2026-05-30T19:45:01+00:00

In Scala, I’d like to do: class Identifier(val str: String) { override def toString():

  • 0

In Scala, I’d like to do:

class Identifier(val str: String) {
    override def toString(): String = str
}

class Variable(t: Type, name: Identifier, mutable: Boolean) {
    override def toString(): String = name
}

But I can’t because Scala won’t implicitly convert name in Variable#toString()‘s definition to a String. Is there a way this can be achieved ?

To be clear: I don’t want to define an additional method like:

object Identifier {
    implicit def idToString(x: Identifier): String = x.str
}

I’d like the toString() method to be called to do the conversion.

  • 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-30T19:45:03+00:00Added an answer on May 30, 2026 at 7:45 pm

    Try putting an explicit toString() call after calling name in Variables toString method like so:

    override def toString() = name.toString()
    

    Here you will explicitly call the method converting Variable to a string, thus telling the compiler exactly what you want.

    .. Unless you really require the method to be implicit…

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

Sidebar

Related Questions

In Scala, how can I do something like this: def cast [Type] (x: _
In Scala, if I have a simple class as follows: val calc = actor
Scala's handling of superclass constructor parameters is confusing me... with this code: class ArrayElement(val
Scala doesn't have type-safe enum s like Java has. Given a set of related
scala.math.ScalaNumber is a Java file which looks like this: public abstract class ScalaNumber extends
Scala Where can differences between a class and a type be observed in Scala
The Scala String method (in class StringOps ) stripMargin removes leading whitespace from each
scala> class A defined class A scala> trait T extends A { val t
Does Scala support something like dynamic properties? Example: val dog = new Dynamic //
in scala play framework I seen this code: abstract class AnalyserInfo case class ColumnC(typeName:String,fieldName: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.