![]() |
|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||||
|
||||
general Java questions
How do you typically handle the situation when you need a method to return multiple values from different types?
I thought of a few solutions, but none are perfect: 1) create an object which has those different types / primitives and use it as the return type 2) create an object with 50 gazillion different constructors, each constructor has a different combination of types and / or primitives, for every conceivable return combination 3) create an object that is an arraylist of arraylist, which each arraylist containing a different type or wrapped primitive
__________________
SageTV server & client: Win 10 Pro x64, Intel DH67CF, Core i5 2405s, 8 GB ram, Intel HD 3000, 40GB SSD system, 4TB storage, 2x HD PVR component + optical audio, USB-UIRT 2 zones + remote hack, Logitech Harmony One, HDMI output to Sony receiver with native Intel bitstreaming |
#2
|
||||
|
||||
Without knowing more about what your method is... it's a little hard to offer advice. But in general, if you can return a concrete return type, ie, an object or primitive, then the underlying code will probably be easier to understand. If you return a 2d array of return values, then you'll need to really document what all the possible values are.
Maybe your solution lies not in the return type but in the method itself. If you have a single method that return so many different return types, then maybe you should create different methods?
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#3
|
||||
|
||||
Here's an example. Method needs to return:
* calculated value - int, double, etc * boolean - true or false indicating did the calculation succeed, fail, fall within a certain range, etc * message text - String of success or failure reason, and there could be a number of different reasons it succeeded or failed That is just one example. I can think of a bunch of different scenarios where I would need more and multiple return types.
__________________
SageTV server & client: Win 10 Pro x64, Intel DH67CF, Core i5 2405s, 8 GB ram, Intel HD 3000, 40GB SSD system, 4TB storage, 2x HD PVR component + optical audio, USB-UIRT 2 zones + remote hack, Logitech Harmony One, HDMI output to Sony receiver with native Intel bitstreaming |
#4
|
||||
|
||||
If you expect the calculation to succeed most of the time, and the other values are just to handle error cases, then you should probably just return the calculated value on success and throw an exception on failure. That way you can use different exceptions to indicate different failure modes and parametrize the exceptions any way you like with additional info. This is basically what exceptions are for.
If it's a case where one calculation produces several values of differrent types in the normal success case, the natural thing to do would be to wrap those different types up in a class that represents a compound object with various properties such as name, age, serial number, etc. If neither of those cases describes your scenario, then maybe you could be more specific about what you're trying to calculate and what the different result cases are.
__________________
-- Greg |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
General questions | Dalgar | The SageTV Community | 5 | 06-17-2008 12:20 PM |
General rule on java updates? | btrcp2000 | SageTV Software | 1 | 11-11-2007 12:02 PM |
A few general Questions before I.... | jaminben | SageTV Software | 7 | 09-23-2007 12:41 PM |
Some general questions | tbil99 | SageTV Software | 20 | 02-22-2005 12:36 PM |
a few general questions... | joesh | SageTV Recorder Software | 1 | 05-26-2004 07:32 AM |