This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Handing a method it's own output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Handing a method it Watch "Handing a method it New topic
Author

Handing a method it's own output

Rian Nolan
Greenhorn

Joined: Jun 21, 2006
Posts: 9
Hi there

If I have (for instance) a method that takes an int and a String:
...what is the JAVA way of handing the output of the method back in to the method multiple times?

I figure I could nest it:

...but I'm not sure that that feels like the way it should be done.

Is there a "standard" way?

Full disclosure - I may just be trying to save myself from a nitpick here ;-)

Cheers,
Brian
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1367
    
  18
There are a gazillion (scientifically speaking) ways to skin a cat, but in general you'll probably do well with something like this:



The second one is confusing, has the potential for bugs, (and, pardon me for mentioning it) really ugly
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1367
    
  18
So to nitpick your snippet...



Please check the style guide for the correct naming of identifiers...

It could be written a little more succinctly (arbitrary values chosen instead of foo and bar).



Rian Nolan
Greenhorn

Joined: Jun 21, 2006
Posts: 9
...so I have saved myself a private nitpick by undergoing a public one?
Way to go - me.

Thanks for that Katrina - it DOES look and feel more readable.
Ever onward with Java-4b (Say)...
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1367
    
  18
Ah, but it saved you an extra round trip on Say 4b... so it must have been worth it!
Rian Nolan
Greenhorn

Joined: Jun 21, 2006
Posts: 9
WELL worth it Katrina

Thanks a millon!
Brian
 
Don't get me started about those stupid light bulbs.
 
subject: Handing a method it's own output