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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:16:50+00:00 2026-05-24T10:16:50+00:00

In Java, I would do something like class MyDate extends java.util.Date { public String

  • 0

In Java, I would do something like

class MyDate extends java.util.Date {
  public String toString() { ... }
}

MyDate date = new MyDate

A little bit clunky. In Scala, is it possible to override toString whilst still using regular java.util.Date instead of MyDate. I have an inkling implicits are involved but would be happy to use any technique

  • 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-24T10:16:51+00:00Added an answer on May 24, 2026 at 10:16 am

    Implicit conversions can only work if the type being converted does not already have a method with a given signature. As everything has a toString, it is not possible to override this by pimping.

    What you might do is use a typeclass (akin to scalaz.Show) which looks like this:

    trait Show[-A] {
      def show(a : A): String
    }
    

    Then you can use show everywhere instead of toString. Ideally what you want then is to make the Show[Any] instance a very low priority implicit.

    implicit val DateShow = new Show[Date] { def show(d : Date) = "whatever" }
    
    trait LowPriorityShows {
      implicit val AnyShow = new Show[Any] { def show(a : Any) = a.toString }
    }
    

    P.S. The reason I would not suggest using scalaz.Show is that the return type is List[Char], which is just not practicable for most uses

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

Sidebar

Related Questions

I want to write in java something like this: public class MyMatcher { public
In Java, I would do something like: Thread t = new MyThread(); t.start(); I
I am trying to create a class say MyStack that would implement a java.util.collections
I want something like this: public abstract class ListenerEx<LISTENER, PARENT> implements LISTENER { PARENT
I'm wondering if there is something like Hotswap/HotDelpoy/JRebel (known from Java World) in .NET
In java i would like to read a file line by line and print
I would like to build a regexp in Java that would be passed in
Is there something like anonymous inner classes (used in Java) in C#? I explain
What is the analog in Scala of doing this in Java: public class Outer
I want to create a Java class with two generic types. public class BinaryContractInfo<T,

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.