• Post Reply Bookmark Topic Watch Topic
  • New Topic

Boolean Return Value  RSS feed

 
Mike Mattos
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public boolean isFull(){ //generally full
if(parcelIsFull() || hcparcelIsFull() || noSharingParcel())
return true;
}

I want to know why i get this error

missing return statement

I have the value written as 'true' boolean as the returning value.
 
Shinelin Samuel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

In this code, Java does not know what to return if the condition fails.

you should have a return statement at the end of the method or inside else section.


Regards,
Shinelin
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every execution path has to return the defined type. As the previous poster wrote, when your 'if' condition is false, the compiler doesn't know what to return.

you can fix it in several ways, the easiest being something like:

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or simply:

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another ingrate multiposter.
http://www.java-forums.org/new-java/26162-boolean-return-value.html#post107265
http://www.daniweb.com/forums/thread264035.html#
http://forums.sun.com/thread.jspa?threadID=5429967

And nary a word of thanks on any of the forums.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, please Be Forthright When Cross Posting To Other Sites.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!