aspose file tools*
The moose likes Beginning Java and the fly likes returning multiple types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "returning multiple types" Watch "returning multiple types" New topic
Author

returning multiple types

Gamb Rockwell
Greenhorn

Joined: Dec 09, 2003
Posts: 25
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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

Joined: Nov 24, 2000
Posts: 776
I use List rather than an array of Object.

Just a thought.

Guy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: returning multiple types