Home arrow static arrow Java Programming [Archive] - help with a toString method
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - help with a toString method
This topic has 22 replies on 2 pages.    « Previous | 1 | 2 |

Posts:19,725
Registered: 9/26/01
Re: help with a toString method  
Aug 3, 2004 10:33 AM (reply 15 of 22)



 
I don't understand what the 'surprise' is about.

For example, you're debugging in your IDE and hover
over an object. It gives you the toString result of
it, and you say "oh, I didn't know it was one of
THOSE, no wonder it's not working." Not a common
occurrance.

Ok, and like I said, if the default toString() implementation were:
className@address[prop1=value1, prop2=value2, ...]
instead of the very-unuseable:
className@address

Then you'd still see the classname and still be able to say "oh, I didn't know it was one of THOSE...".
Anyway, I don't know if you're agreeing with me or not...
 

Posts:6,750
Registered: 1/25/04
Re: help with a toString method  
Aug 3, 2004 10:47 AM (reply 16 of 22)



 
Yes, I'm agreeing with you that it's stupid. I'm also pointing out that there is at least one obscure way in which the current implementation could be useful. Sometimes. Maybe.
 

Posts:31,095
Registered: 4/30/99
Re: help with a toString method  
Aug 3, 2004 11:39 AM (reply 17 of 22)



 
I have worked with applications where the toString() method has been overridden to display all of the data members of the object. It sounds like a good idea, but when the data members are not primitives but references to objects where the toString() method has been overridden to display all of the etc etc etc, or worse, Lists of such objects, then it becomes unreadable.
 

Posts:27,518
Registered: 11/3/97
Re: help with a toString method  
Aug 3, 2004 3:57 PM (reply 18 of 22)



 
They probably wanted to keep reflection out of the
java.lang package, although they might be using it
under the covers elsewhere and I don't know. They
could also have used native code.

But in any case, how in the world does the default
toString() implementation ever cut the mustard? It's
never useful by default.
className@memoryAddress - yeah, that's real
useful.

I find it useful.
 

Posts:2,830
Registered: 9/1/03
Re: help with a toString method  
Aug 3, 2004 4:00 PM (reply 19 of 22)



 
They probably wanted to keep reflection out of the
java.lang package, although they might be using it
under the covers elsewhere and I don't know. They
could also have used native code.

But in any case, how in the world does the default
toString() implementation ever cut the mustard? It's
never useful by default.
className@memoryAddress - yeah, that's real
useful.

I find it useful.

going to explain why :) ?
 

Posts:27,518
Registered: 11/3/97
Re: help with a toString method  
Aug 3, 2004 4:01 PM (reply 20 of 22)



 
I have worked with applications where the toString()
method has been overridden to display all of the data
members of the object. It sounds like a good idea, but
when the data members are not primitives but
references to objects where the toString() method has
been overridden to display all of the etc etc etc, or
worse, Lists of such objects, then it becomes
unreadable.

That can happen.

But most object instances do not take that form.

And sometimes that information is not only useful but essential, even if it is hard to read.

Of course there are alternatives that are more readable.
 

Posts:2,830
Registered: 9/1/03
Re: help with a toString method  
Aug 3, 2004 4:02 PM (reply 21 of 22)



 
They probably wanted to keep reflection out of
the
java.lang package, although they might be using
it
under the covers elsewhere and I don't know.
They
could also have used native code.

But in any case, how in the world does the default
toString() implementation ever cut the mustard?
It's
never useful by default.
className@memoryAddress - yeah, that's real
useful.

I find it useful.

going to explain why :) ?

i find it useful too, however. it tells me immediately i am doing the wrong
thing with this object if i ever see it.
 

Posts:27,518
Registered: 11/3/97
Re: help with a toString method  
Aug 3, 2004 4:15 PM (reply 22 of 22)



 

I find it useful.

going to explain why :) ?

Some developer tells me that my layer is wrong because they "know" that they set an attribute and passed the DTO do me and yet the value isn't showing up.

I tell them that they are not passing the DTO that they think they are but instead they are passing another. They claim that that can't possibly be true because they "know" it is the same.

I then either force them to add the toString() call or add it myself and then demonstrate that the values are not the same.

Sometimes I do it myself for the same reason. But usually by then I am already certain that I am not using the same object but I want to do a sanity check to confirm it.
 
This topic has 22 replies on 2 pages.    « Previous | 1 | 2 |