Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

return value???  RSS feed

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have 2 class....class A and class B....in class A i want to call a method in class B and send 2 parameter(v1 and v2).....in class B, it will transform v1 and v2 into v3 and v4.....the problem is...i need to send back the 2 new variables(v3 & v4) to class A....we can only return one value.....so, what i can do to send v3 & v4 back to class A???
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can return an array if the values are of the same type or you can send back an object that contains the two values as it's properties.
 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i send back an object does that means after that i can separate it into 2...???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, create setter and getter methods for the two properties.

Set the two properties from within your method, return the object and then read the properties to get the values.
 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry...i cant really understand u....can u give me some example...
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If v1 and v2 are objects instead of primitives, the easiest solution is an Object array (or a specific array if they have the same class). Here's a trivial example:This will output the following.Does that clarify it? Ben's suggestion is to define a class with fields that will hold the returned objects along with a pair of get/set methods (accessors) for each. This class would satisfy the JavaBean requirements, so you might want to look that up at Sun's Java site if you need examples.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this isn't too hard to read.
I tried to make it, simple, terse, and readable, in a short amount of time.




[ February 22, 2005: Message edited by: Ben Souther ]
 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everybody....i manage to solve my problem....thanks to ben and david...i really appreciate the help from both of u...
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii

Can we define a function in A class which can take 2 variables and call the function in B class so that v3 and v4 can be sent to class A ?

Thanks
Regards
M.Kartik
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Kartik Mahadevan:
Hii

Can we define a function in A class which can take 2 variables and call the function in B class so that v3 and v4 can be sent to class A ?

Thanks
Regards
M.Kartik



Yes
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!