A Programming Job Interview Challenge #7 - Coins of The Round Table

A Programming Job Interview Challenge #7 - Coins of The Round Table

An ArrayList hold objects, so when you insert a ValueType into it, it will be boxed and become an object. When you compare List[0] to List[1] you are comparing references, and they will never be the same because they are pointing to different objects. This is the reason for getting the false in both comparison. It is true that in the second comparison you are comparing a double and an int ( 2.0 and 2), but that is not why you get false, it is due to the Boxing.

Read More:

http://www.dev102.com/2008/06/09/a-programming-job-interview-challenge-7-coins-of-the-round-table/

Thanks

Leave a Reply

You must be logged in to post a comment.