The Artima Developer Community
Sponsored Link

Java Answers Forum
Interpreting toString() output of Class Objects

3 replies on 1 page. Most recent reply: Aug 9, 2002 2:01 PM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Guido

Posts: 38
Nickname: kiethb
Registered: May, 2002

Interpreting toString() output of Class Objects Posted: Aug 9, 2002 1:14 PM
Reply to this message Reply
Advertisement
Is there some reference material as to how to understand the parsed contents of a string representation of a class? I was working on fixing a bug in my program and sent the class info to the console, there I noticed some differences between the same element types in the class. I noticed that some gave an invalid message and others didnt but all they all worked fine(that wasn't necessarily the problem I was chasing in the first place). now I want to learn how to tell what is wrong with it so as to know if I need to tighten something up or not.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Interpreting toString() output of Class Objects Posted: Aug 9, 2002 1:34 PM
Reply to this message Reply
> Is there some reference material as to how to
> understand the parsed contents of a string
> representation of a class?

No, because every class can override toString(), so there is no guarantee that it has any particular format or meaning. If you want to get specific information about objects, you should be using reflection, instead. For instance, look at the difference between someObject.toString(), someObject.getClass().toString() and someObject.getClass().getName().

Guido

Posts: 38
Nickname: kiethb
Registered: May, 2002

Re: Interpreting toString() output of Class Objects Posted: Aug 9, 2002 1:38 PM
Reply to this message Reply
thanks matt, I will give it a shot.

Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: Interpreting toString() output of Class Objects Posted: Aug 9, 2002 2:01 PM
Reply to this message Reply
> Is there some reference material as to how to
> understand the parsed contents of a string
> representation of a class? I was working on fixing a
> bug in my program and sent the class info to the
> console, there I noticed some differences between the
> same element types in the class. I noticed that some
> gave an invalid message and others didnt but all they
> all worked fine(that wasn't necessarily the problem I
> was chasing in the first place). now I want to learn
> how to tell what is wrong with it so as to know if I
> need to tighten something up or not.

-IMO-
If it isn't overridden the toString() will return.
getClass().getName() + '@' + Integer.toHexString(hashCode())

It is a good practice to override toString(), I believe that it should return information about the state of the object, this can be used as a valuable tool during development and debugging.

HTH

Flat View: This topic has 3 replies on 1 page
Topic: Can anyone please help with this problem Previous Topic   Next Topic Topic: run java program from java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use