Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualShaquil

Posted 24 May 2013 - 07:30 AM

If you don't define toString() it will be inherited from Object, that defines it as

getClass().getName() + '@' + Integer.toHexString(hashCode())

 

 

That's more along the lines of what I was looking for, thanks. By the way, is that Integer.toHexString(hashCode()) supposed to be the object's location in the heap?

 

Andy747 mentioned that it saves your program from crashing, but shouldn't that be a compile-time error anyway? If I'm trying to convert an object to a string, and toString() isn't explicitly overridden, doesn't that imply that I made a typo, and I don't actually want to convert the object itself into a string?

 

I'm sure there's a good reason why it does this, so that's why I'm asking.


#1Shaquil

Posted 24 May 2013 - 07:28 AM

If you don't define toString() it will be inherited from Object, that defines it as

getClass().getName() + '@' + Integer.toHexString(hashCode())

 

 

That's more along the lines of what I was looking for, thanks.

 

Andy747 mentioned that it saves your program from crashing, but shouldn't that be a compile-time error anyway? If I'm trying to convert an object to a string, and toString() isn't explicitly overridden, doesn't that imply that I made a typo, and I don't actually want to convert the object itself into a string?

 

I'm sure there's a good reason why it does this, so that's why I'm asking.


PARTNERS