Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Question on when toString() method is called

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The above code prints
Krishna
Inside String method

I umderstand StringBuilder has it's own toString method so it calls that method and prints Krishna . I am trying to find out what triggers calling of toString method. println method calls toString method on the argument that is passed ? I checked API .println method actually calls Strin.valueOf methos on the argument that is passed. Can someone explain and trace how exactly toString method is called ?

Thanks,
Veena
 
Sheriff
Posts: 3123
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Veena Pointi wrote:Can someone explain and trace how exactly toString method is called ?


According to the documentation for String.valueOf(Object obj), if the argument is null, then a string equal to "null" [is returned]; otherwise, the value of obj.toString() is returned.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! I don't know how did I miss to read this ,although I thoroughly read few times. Thank you very much Ron.
 
We're all out of roofs. But we still have tiny ads:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic