This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning multiple types

 
Gamb Rockwell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to return multiple values of different types from a java method. What is the best way that I should use to achieve that.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define a new class with member variables to hold all the values. Have your method return an instance of this new class with the members initialized to the values you want to return.
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I sometimes using array of Object (Object[]) to store multiple data type in return of method...

By the way, I dont know whether it is a bad design or not...

Correct me if I am wrong
Hope this helps
daniel
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use List rather than an array of Object.

Just a thought.

Guy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic