aspose file tools*
The moose likes Beginning Java and the fly likes return - statement I don't understand Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return - statement I don Watch "return - statement I don New topic
Author

return - statement I don't understand

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Hello,
what does this mean:
return !hasMoreJobs () ? null : jobs [jobIndex++];
Thanks.
Thomas
Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
Thomas,

can also be written als

Using the first notation, is considerable shorter.
Marcel
[ August 16, 2002: Message edited by: Marcel de Jong ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Or to paraphrase to a slightly more readable version:

No difference, just relies on the fact that things are easier to understand if you don't have to get your head around a negation first...
Dave
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
booleanTest ? expression1 : expression2
This is the only ternary operator in Java. As already expressed, it's a shorthand if-else construct. If the boolean test is true, then the first expression is evaluated and returned; otherwise the second expression is evaluated and returned.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Even if you keep the ternery operator, ditching the negation is more readable style:
return hasMoreJobs () ? jobs [jobIndex++] : null;


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
 
subject: return - statement I don't understand