Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Alessandro Longheu
http://www.diit.unict.it/users/alongheu
alessandro.longheu@diit.unict.it
Generics in Java
1
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
Vantaggi:
Fornisce una migliore gestione del type checking durante la
compilazione
Evita il casting da Object. I.e., invece di:
2
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
4
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
5
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
6
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
9
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
LinkedList<Integer>
14
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
Wildcards
void printCollection(Collection<?> c) {
for (Object e : c) { System.out.println(e);}}
16
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
17
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
20
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
23
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
24
A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010
25