OK, who forgot the toString method

Everyone (well, Java programmers anyway) knows how useful the toString method is.

You can call it explicitly on a class to get some sort of String representation of that class.

But it’s also called implicitly in some situations too.

Like when concatenating Objects to Strings.

Or when calling toString on a Collection of Objects (toString will be called on each object in the Collection).

Which makes it really really annoying when somebody forgets to put a toString method on their class.

Then you get the default Object class implementation of toString which looks something like org.boncey.beans.Bob@d652c1.

Not very useful at all really.

Now if that is in some code that somebody wrote in-house you can fix it, or badger them to fix it.

But when it’s in the JDK you’re stuck with it.

So, hopefully, one day, somebody at Sun will notice the lack of a toString method on java.util.regex.Pattern and bloody well add one!

2 thoughts on “OK, who forgot the toString method”

Comments are closed.