Chapter 13. Generic Programming

   


  • Why Generic Programming?

  • Definition of a Simple Generic Class

  • Generic Methods

  • Bounds for Type Variables

  • Generic Code and the Virtual Machine

  • Restrictions and Limitations

  • Inheritance rules for Generic Types

  • Wildcard Types

  • Reflection and Generics

Generics constitute the most significant change in the Java programming language since the 1.0 release. The addition of generics to JDK 5.0 is the result of one of the first Java Specification Requests, JSR 14, that was formulated in 1999. The expert group spent about five years on specifications and test implementations.

Generics are desirable because they let you write code that is safer and easier to read than code that is littered with Object variables and casts. Generics are particularly useful for collection classes, such as the ubiquitous ArrayList.

Generics are at least on the surface similar to templates in C++. In C++, as in Java, templates were first added to the language to support strongly typed collections. However, over the years, other uses were discovered. After reading this chapter, perhaps you will find novel uses for Java generics in your programs.


       
    top



    Core Java 2 Volume I - Fundamentals
    Core Java(TM) 2, Volume I--Fundamentals (7th Edition) (Core Series) (Core Series)
    ISBN: 0131482025
    EAN: 2147483647
    Year: 2003
    Pages: 132

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net