Posted: Fri Jul 13, 2007 10:49 am Post subject: RE:A challenge
And which type is more specific? The array, or the interface?
Sponsor Sponsor
Aziz
Posted: Fri Jul 13, 2007 11:56 am Post subject: RE:A challenge
Specific? The array, int[], or course. Collection<Integer> could be any Collection<Integer>, such as List<Integer>, LinkedList<Integer>, HashSet<Integer> etc etc.
Alright, I get it. I'm not going to reveal it though....
A hint: The actual problem resides in the bar() method's declaration
UnusedUsername
Posted: Fri Jul 27, 2007 9:39 am Post subject: Re: A challenge
Is it that bar() should return a Collection of Integers instead of a int[] because in the for-each loop, the Integer class would be autoboxed to an int anyway?
You're close, but for the wrong reason, UnusedUsername.
UnusedUsername
Posted: Sun Aug 05, 2007 4:24 pm Post subject: Re: A challenge
Is the reason because the Integers would be unboxed (not autoboxed) to a int?
But if the return type was a Collection<Integer>, performance should be slower because of the boxing, but perhaps this is offset by the fact that Collection<Integer> is more general than int[]?
I'm still pretty clueless though.
wtd
Posted: Sun Aug 05, 2007 10:34 pm Post subject: RE:A challenge
The return type of "int[]" is overly specific. Using an interface to specify the return type allows for more freedom to change the code in the future.
Chinmay
Posted: Mon Feb 04, 2008 8:58 pm Post subject: Re: RE:A challenge
wtd @ Wed Jul 11, 2007 7:11 pm wrote:
Aziz is starting to think along the right lines.
I dont have any experience with JAVA but whatever I learn I try to learn perfect
Dosnt the baz class have to be public class and contain a main method otherwise this would not compile since it wouldnt make it an application
Sponsor Sponsor
Tony
Posted: Mon Feb 04, 2008 9:19 pm Post subject: Re: RE:A challenge
Chinmay @ Mon Feb 04, 2008 8:58 pm wrote:
it wouldnt make it an application
A piece of code does not need to be "an application" to compile and be valid. Think library files.