Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A challenge
Index -> Programming, Java -> Java Tutorials
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: 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
Sponsor
sponsor
Aziz




PostPosted: 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.

Still don't see what problem this is leading to.
Aziz




PostPosted: Fri Jul 13, 2007 12:04 pm   Post subject: RE:A challenge

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




PostPosted: 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?
wtd




PostPosted: Fri Jul 27, 2007 12:12 pm   Post subject: RE:A challenge

You're close, but for the wrong reason, UnusedUsername. Smile
UnusedUsername




PostPosted: 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




PostPosted: 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




PostPosted: 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 Mr. Green

Rolling Eyes 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

BooHoo
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 39 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: