Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Generics and Collections in Java 5

Generics and Collections in Java 5

Ratings:
(0)
|Views: 158|Likes:
Published by api-3830461

More info:

Published by: api-3830461 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/01/2015

pdf

text

original

Generics and Collections in Java 5
Maurice Naftalin
naftalin@morninglight.co.uk
Philip Wadler
wadler@inf.ed.ac.uk
This version is a draft. Please send comments to the addresses above.
Copyrightc
\ue0002005 O\u2019Reilly Media, Inc.
2
Contents
I Introduction to Generics
7
1 Gettingstarted
11

1.1 Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 1.2 Boxing and unboxing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 1.3 Foreach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 1.4 Generic methods and varargs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 1.5 Assertions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 1.6 Summingup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19

2 Subtyping and wildcards
21

2.1 Subtyping and The Substitution Principle. . . . . . . . . . . . . . . . . . . . . . . . . .21 2.2 Wildcards with extends. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 2.3 Wildcards with super. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23 2.4 The Get and Put Principle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 2.5 Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 2.6 Wildcards vs. type parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29 2.7 Wildcardcapture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31 2.8 Restrictions on wildcards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32

3 Comparison and bounds
35

3.1 Comparable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 3.2 Maximum of a collection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37 3.3 A fruity example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39 3.4 Comparator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 3.5 Enumeratedtypes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 3.6 Multiplebounds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 3.7 Bridges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 3.8 Staticmembers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 3.9 Nestedclasses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51 3.10 How erasure works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52

4 Evolution not revolution
57
4.1 Legacy library with legacy client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
4.2 Generic library and generic client. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
3

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->