• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what's the difference between these two methods?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello!

there are two methods:

public boolean m1(){
return true;
}

public boolean m2(){
return (true);
}

In my opinion ,these two methods have the same function.
Why some place use m2()?

best regards.
[ June 03, 2007: Message edited by: Cao Bin ]
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Absolutely no difference. You can place paranthese about every expression in Java, so the following is absolutely legal
Why some people write

return (true);


I cannot say, you shouldn't do it, as it is unnecessary. Maybe you need to do so in other languages...
[ June 03, 2007: Message edited by: Sasha Ruehmkorf ]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well...!
I too feel the same. There is not difference between those two methods.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java Language, () is not required to return any value,even if its a calculation.e.g

return 3+6-2;
return "sadh"+ "na";

I believe that use of () with return in java is effect of other languages like c,cpp .
So return true and return (true) are same.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic