SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-19-2010, 06:26 PM
korben_dallas's Avatar
korben_dallas korben_dallas is offline
Sage Icon
 
Join Date: Oct 2004
Location: USA
Posts: 1,250
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
Reply With Quote
  #2  
Old 06-19-2010, 07:06 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
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?
Reply With Quote
  #3  
Old 06-19-2010, 07:20 PM
korben_dallas's Avatar
korben_dallas korben_dallas is offline
Sage Icon
 
Join Date: Oct 2004
Location: USA
Posts: 1,250
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
Reply With Quote
  #4  
Old 06-19-2010, 10:58 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -6. The time now is 06:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.