Quote:
|
Originally Posted by Tim Tyler
Sometimes objects are written in a way that toString() provides a textual
representation of the contents of the object.
Otherwise, it's a case of using reflection to access the data.
|
I know I'm responding to an old post, but maybe this will be useful to some others who happen upon this thread.
It is true that some objects override the
toString() method to return something descriptive and useful. In particular, the
HashMap class (and most implementors of the
Map interface) do this, printing their key/value pairs in a human-readable form. This works recursively, since
toString() is also called on the keys and values, so for example
HashMaps of
HashMaps are displayed correctly.
The formatting is not as nice as Perl's
Data::Dumper class though.
Note: I mention this because the OP's question specifically used the example of a Perl
HASH, so if that is all that the OP is trying to do, this might be sufficient.