• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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

 
Ranch Hand
Posts: 422
  • 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: 24203
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
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.
 
We're all out of roofs. But we still have tiny ads:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic