• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
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
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.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW everything in Java is pass-by-value, primitives and object references.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic