String buffer

Hi I have the followig method
      public String toString()
      {
        StringBuffer buff = new StringBuffer();
        buff.append("This is a test message");
        return buff.toString      
      }

This returns  "" basically nothing
but if I use
                 return new String(buff.toString());

This returns the required result.

Cant understand :(

LVL 3
applekannaAsked:
Who is Participating?
 
objectsCommented:
they both should return the same.
0
 
CEHJCommented:
That won't compile at the moment

>>return buff.toString      

should be

return buff.toString();      

0
 
badprogrammerCommented:
The above code wont compile
because >>> return buff.toString <<< should actually be buff.toString()
and yeah they both should give the same output.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
badprogrammerCommented:
Sorry it should be return buff.toString().
0
 
applekannaAuthor Commented:
Sorry but that was a typo there .....
0
 
applekannaAuthor Commented:
got it I called it just as

MyObject.toString();

Should have encapsulated it in a System.out.

Thx for ur help
0
 
objectsCommented:
0
 
CEHJCommented:
8-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.