Depends. If the returned types are two unrelated types then you'd have to return an Object[], which negates the value of type safety, IDE support, etc. I tend to use inner classes or utility classes instead--but that's just me.
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
posted
0
Objects that manage pairs of items or values are quite
common. They are also easy to expand (extend) to handle
more items and mixed item types. So by using an object
you are on a very good track.
Jim ... ...
BEE MBA PMP SCJP-6
Jacob Sonia
Ranch Hand
Joined: Jun 28, 2009
Posts: 164
posted
0
But should i use a collection or just an object array would suffice for two objects
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
I would use an object which encapsulates the two values, not an array or collection.
What advantage this has over using Object array. I agree there is type checking and meaningful getters. But, for one time returning of two objects, which is preferable. I mean, i would like to know the pros and cons of each
if you return an array, then your code will be sprinkled with
//or something like that - i may have the casting wrong
If you write a new class that encapsulates both A and B as member objects, you could write that containing class so that it knows what method to call...
Never ascribe to malice that which can be adequately explained by stupidity.
Sha Jar
Greenhorn
Joined: Mar 02, 2010
Posts: 23
posted
0
Jacob Sonia wrote:[code]
Which is considered good coding skills?
The general rule is that a method should return a value of a specific type.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Function returning two reference variables