• Post Reply Bookmark Topic Watch Topic
  • New Topic

function return type  RSS feed

 
Steve Mutonshi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
********************************************

***************

uestion: if I change "void doSomehing()" into "boolean doSOmething()" it still works fine. I know it look awkward, but doesn't it cause any problem ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a return statement inside the method? Leaving the body of the method out wasn't the best idea.
 
Steve Mutonshi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


wondering if change it into


Does it cause any problem (I know it compiles and runs fine and make more sense if it is "void") if use boolean return type ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, because you return a boolean, the compiler is happy. When you call a method, you don't need to actually use the returned value. But then, it doesn't make much sense to define and return a value if it's not going be used, does it?
 
Steve Mutonshi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:But then, it doesn't make much sense to define and return a value if it's not going be used, does it?

Avtually, it doesn't make much sense to define and return a value if it's never used; there may well be a good case for returning something that isn't used in every case.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!