Generics: CS 305 & 503 Lecture notes

Data Structures & Algorithms Lecture Notes

15 September 2009 • Generics


Outline

  • Polymorphism

  • Generics

    • Basics

    • Implementation via erasure.

    • Properties

  • Wildcards

  • Bounded type variables.

generic can

Polymorphism

Object Polymorphism

Problems.

Problems..

Object-Polymorphism Fixes

Wishful Thinking

Type-Variable Example

Generics

Generic Type Variables

Generic Class Names

Using Type Variables

Type Variables vs new

Type Variables vs static

Type Variables vs Primitives

Implementing Generics

History

Erasure

Erasure Example.

Erasure Example..

Erasure Example...

Erasure Example....

Observations

Repercussions

Type Variables vs new

Type Variables vs Primitives

Generics vs. Inheritance

Violating Run-time Guarantees

Example

Erasure Strikes Again

Type (In)Compatability

Polymorphism Exiled

Wildcards

Wildcard Properties

Generics Hierarchy

misbegotten family trees

When Types Matter

Bounded Wildcards

Bounded Wildcard Properties

Bounded Type Variables

Multiple Bounds

Summary

References

Credits


This page last modified on 16 September 2009.

Creative
    Commons License