File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes return - problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return - problem" Watch "return - problem" New topic
Author

return - problem

John Frank
Greenhorn

Joined: Jun 28, 2006
Posts: 4
sorry to bother again, but i dont get it.



In the maybeNew class, there are 2 returns (they are not seperated with a else).

-
The example before was clear but i ll explain (just to be sure)



Lets say giveSecret was 5, so the return 42 makes the value 42 now.
-
Back to the other code. Where do the returns go? -> maybeNew = 0?
But why are there 2 returns. Does the compilier make the value first 1 and then 0? Isnt it useless to use 2 returns or just for the example?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

If the first return is executed, then the method is all done. No other code in the method is executed (including, of course, that second return.)

This code is quite odd -- there are all kinds of things that I'm sure you didn't intend here. You should probably ask for more help understanding what's going on.

One important thing I'll get you started on: after this code, the array m4a will contain 20 Mix4a objects. Every one of them will have a "counter" member equal to 1. Can you explain why?


[Jess in Action][AskingGoodQuestions]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

This might be easier to see with proper indentation...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
John Frank
Greenhorn

Joined: Jun 28, 2006
Posts: 4
oh....didnt know the thing, thought there must be an "else".

well this is an example from chapter 4 "Head first Java". Guess it should show the "return" ^^ . The container "thing" was explained before. thanks!
[ July 03, 2006: Message edited by: John Frank ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return - problem