This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Wanted: How to return multiple values when using java.lang.reflection.invoke? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Wanted: How to return multiple values when using java.lang.reflection.invoke?" Watch "Wanted: How to return multiple values when using java.lang.reflection.invoke?" New topic
Author

Wanted: How to return multiple values when using java.lang.reflection.invoke?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
I want to write a little function that solves the following equation for real values only (as opposed to imaginary):

a*x^2 + b*x + c = 0;

My attempt is working, but I am not successfully passing back the values r1 and r2 to the calling function.

Is this possible in java? I thought everything except primitives were passed by reference in java!
Thanks
Siegfried
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You don't say what r1 and r2 are, and I'm not clear on what reflection has to do with anything, nor how pass-by-reference is related to this. This sounds like a case where you've built yourself up a nice big hairy mudball in your brain!

I can answer what I think is the root question here. A Java method can only return one value -- one primitive or one object reference. If you need to return two numbers from a method, then you need to bundle them up together somehow. Return them as a two-element array, or define a class to hold them and return an instance of that.


[Jess in Action][AskingGoodQuestions]
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
You could create a special class that simply holds the two values:

An instance of that whis would be the object reference to return from your method.

[ September 28, 2006: Message edited by: Jean-Francois Briere ]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
BTW everything in Java is pass-by-value, primitives and object references.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wanted: How to return multiple values when using java.lang.reflection.invoke?
 
Similar Threads
Drawing graphs for mathematical functions using Java
help with this problem
java trim function is not working when reading excel data
JSF and JavaScript
graph plotting