Skip to main content
1 of 3
Rollerball
  • 13.2k
  • 26
  • 99
  • 169

What actually happens in the compiler in this case

I have a small question, given the following snippet:

StringBuilder stringBuild = new StringBuilder(3); stringBuild.append("hello"); System.out.println(stringBuild+2); // if I omit the (+2) bit hence only stringBUild it works 

Does it call automatically toString() on object only in some circumstances? (circumstances: either no operation at all or a previous string contatanation)

Rollerball
  • 13.2k
  • 26
  • 99
  • 169