Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

return - problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Would you like to try a free sample? Today we are featuring tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic