O'Reilly logo

Ivor Horton's Beginning Java®, Java 7 Edition by Ivor Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13

Generic Class Types

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • What a generic type is
  • How you define a generic type
  • How you specify type parameters for a generic type
  • What parameter type bounds are and how you use them
  • What wildcard type specifications are and how you use them
  • How you define bounds for a wildcard
  • How you define and use parameterized methods

Generic class types are not a separate capability from the class and interface types that you have seen in earlier chapters. The facility for defining generic class and interface types is an extension of the ordinary definition of classes and interfaces that you are familiar with that enables you to define families of classes and interfaces.

WHAT ARE GENERIC TYPES?

A generic type, which is also referred to as a parameterized type, is a class or interface type definition that has one or more type parameters. You define an actual class or interface type from a generic type by supplying a type argument for each of the type parameters that the generic type has. It’ll be easier to understand what this means with a concrete example of where and how you could apply the concept.

I’m sure you recall the LinkedList class that you first saw in Chapter 6 and used in an example in Chapter 12. You used the LinkedList class to encapsulate a linked list of Point objects, but the idea of a linked list applies to any set of objects that you want to organize in this way. A linked list is just one example of classes that define objects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required