Skip to Main Content
THE Java™ Programming Language, Fourth Edition
book

THE Java™ Programming Language, Fourth Edition

by Ken Arnold, James Gosling, David Holmes
August 2005
Intermediate to advanced content levelIntermediate to advanced
928 pages
20h 39m
English
Addison-Wesley Professional
Content preview from THE Java™ Programming Language, Fourth Edition

Chapter 11. Generic Types

 

The problem with people who have no vices is that generally you can be pretty sure they're going to have some pretty annoying virtues.

 
 --Elizabeth Taylor

In the Java programming language, the class Object forms the root of the class hierarchy, allowing other classes to deal with arbitrary types of objects by declaring that they work with Object. In Chapter 3 you saw a SingleLinkQueue class that used Cell objects to hold a reference to any Object you wanted in the queue. This provides great flexibility, but with some inconvenience: If you know that the elements in question are String objects, for example, then you have to cast the result of the remove method each time.

This use of Object as a generic reference is also ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The C++ Programming Language, 4th Edition

The C++ Programming Language, 4th Edition

Bjarne Stroustrup
C Programming Language, 2nd Edition

C Programming Language, 2nd Edition

Brian W. Kernighan, Dennis Ritchie
The Go Programming Language

The Go Programming Language

Alan A. A. Donovan, Brian W. Kernighan

Publisher Resources

ISBN: 0321349806Purchase book