Reflect on Your Mistakes
by in CodeSOD on 2024-05-09While Java didn't invent putting a toString
method in the base class of every object, it certainly made it mainstream. The nice thing about the method is that it allows you to turn any object into a string, though it's up to the implementor to decide what a good string representation is. But what if you want to ensure that the object you're handed is really and truly a string, not just something you can convert to a string?
teknopaul's co-worker found their own solution: