Skip to Content
Java Generics and Collections
book

Java Generics and Collections

by Maurice Naftalin, Philip Wadler
October 2006
Intermediate to advanced
284 pages
8h 30m
English
O'Reilly Media, Inc.
Content preview from Java Generics and Collections

Chapter 5. Evolution, Not Revolution

One motto underpinning the design of generics for Java is evolution, not revolution. It must be possible to migrate a large, existing body of code to use generics gradually (evolution) without requiring a radical, all-at-once change (revolution). The generics design ensures that old code compiles against the new Java libraries, avoiding the unfortunate situation in which half of your code needs old libraries and half of your code needs new libraries.

The requirements for evolution are much stronger than the usual backward compatibility. With simple backward compatibility, one would supply both legacy and generic versions for each application; this is exactly what happens in C#, for example. If you are building on top of code supplied by multiple suppliers, some of whom use legacy collections and some of whom use generic collections, this might rapidly lead to a versioning nightmare.

What we require is that the same client code works with both the legacy and generic versions of a library. This means that the supplier and clients of a library can make completely independent choices about when to move from legacy to generic code. This is a much stronger requirement than backward compatibility; it is called migration compatibility or platform compatibility.

Java implements generics via erasure, which ensures that legacy and generic versions usually generate identical class files, save for some auxiliary information about types. It is possible to replace ...

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

Understanding Java 8 Generics

Understanding Java 8 Generics

Ken Kousen
Java Generics and Collections, 2nd Edition

Java Generics and Collections, 2nd Edition

Maurice Naftalin, Philip Wadler
Java 8 Lambdas

Java 8 Lambdas

Richard Warburton

Publisher Resources

ISBN: 0596527756Supplemental ContentErrata Page