J
James Kanze
In C, void * effectively is a supertype of all pointers. So when
you want to write a function for any kind of pointer, you can use:
f( void * );
. In Java, java.lang.Object is a supertype of all reference types.
By this, they can enforce that every object implements toString(),
which make debugging easier: You can print any object o, by printing
the string o.toString(). When you overwrite toString() in your new
class, standard functions immediately start to use this. When it makes
no sense to overwrite a java.lang.Object method in a new class, that
method can usually just be ignored without harm. So one is not forced
to always implement every java.lang.Object method for every little new
class.
Java's java.lang.Object.toString() is exactly the equivalent of
ostream:perator<<( void* ). In other words, totally useless.