Object-Oriented Programming with Java Lecture Notes

25 March 2008 • Generics


Outline

  • Polymorphism

  • Generics

    • Basics

    • Implementation via erasure.

    • Properties

  • Wildcards

  • Bounded type variables.

generic can

Polymorphism

Polymorphism Varieties

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

Arrays vs Inheritance

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 4 March 2008.

Creative
    Commons License