• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return - problem

 
John Frank
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be easier to see with proper indentation...
 
John Frank
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic