• 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: 24211
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