Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 5th, 2007, 07:19 PM
Registered User
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Collection-based for loop syntax question.

In the code fragment for the listAll() method presented on bottom of page 582, Chapter 13, the following code line is used:

for(Object obj : list)

but the class type of input variable list is given as the wildcard specification:
LinkedList<?> list

How can obj, a variable of type Object, be the type identifier for a collection of type LinkedList<?>, which, presumably, can only hold a LinkedList type (where a collection type is substituted for the ? in <?>)?

On page 113 in Chapter 3, where the author first introduced the collection based for loop, he stated:
"The first element [of the for loop] is an identifier of the type that you specify, and the second is an expression specifying a collection of objects or values of the specified type."

It looks like we have a type mismatch here, between the identifier and the collection of the specified identifier type. I realize that type Object can store any other type, and perhaps this syntax works, but nowhere in the book did the author introduce or justify the above syntax. I am still in Chapter 13, but I did peruse Chapter 14 (on Collections), as well as the Index, and I cannot find any further information on this syntax.

Anyone who can shed some light on this topic will be greatly appreciated. If necessary, I will post the result to the Errata cite.


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax for a processing loop dhollis XSLT 3 September 7th, 2006 02:44 PM
Collection-based for loop troubles... stidle BOOK: Beginning Java 2, JDK 5 Edition 0 February 13th, 2006 08:52 PM
syntax question Tachyon Beginning PHP 4 July 14th, 2004 07:40 PM
Syntax question please. savoym VBScript 2 August 12th, 2003 12:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.