• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to interpret results of println when printing user defined object  RSS feed

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the printout of System.out.println("printing projectCollection: "+measurementProjectCollection);
as well as
System.out.println("printing projectCollection: "+measurementProjectCollection.toString());
except the values change after the @:

printing projectCollection: projectContainer.MeasurementProjectCollection@16a9d42

So can anyone tell me how to interpret this? Is it possible that the value of measurementProjectCollection is null, or does that random characters mean there is some kind of value in there.
Im not trying to find out what the actual value is, I dont think that is possible to do in this manner, just if this could still mean this is a null value or not really, plus any other things I might be able to tell from this
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't any interpreting to be done. What you see is simply what the toString() method of that object returns. What you're asking about is what you see when the class doesn't override toString() and leaves that job to the toString() method of Object. You can't tell anything at all from the result.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your class hasn't implemented a toString() method then it must have inherited it from it's parent class. Look at your class's parent class(es) until you find the implementation and then look at the Javadocs for that method and it should explain what the output represents.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to what others had said till now, the following line



typically looks the 'toString()' method has NOT been implemented at all thus leaving it to java.lang.Object's toString() implementation which prints the fully qualified classname followed by the hashcode of the object with an '@' symbol. -- This is the default behavior.

 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Kohanek wrote:
So can anyone tell me how to interpret this? Is it possible that the value of measurementProjectCollection is null, or does that random characters mean there is some kind of value in there.


It means, the value is NOT null. It is a *valid* object and whose hashcode is what being printed. If the object is null, it would simply return the string 'null' in its place.

Im not trying to find out what the actual value is, I dont think that is possible to do in this manner, just if this could still mean this is a null value or not really, plus any other things I might be able to tell from this


As said earlier, it is the hashcode calculated by the Java Runtime Environment and you can override if you wish with the unique data members of an object so as to distinguish it at the runtime.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to the discussion, see "The toString() Method" section at the bottom of this Java Tutorial page.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!