Understanding Generic Programming & Classes in Java at UMD, College Park - Prof. Nelson Pa, Study notes of Computer Science

This document from the university of maryland, college park's department of computer science provides an overview of generic programming and generic classes in java. It explains how to define constructs that can be used with different types, the use of inheritance or type variables for implementation, and the concept of a generic class with one or more type variables. The document also covers valid and invalid types for generic classes and how to define and use them. Students will learn how to define their own generic classes and use type variables to define variable types, method arguments, and return types.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-yxb
koofers-user-yxb 🇺🇸

5

(1)

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Generics
CMSC 132
Department of Computer Science
University of Maryland, College Park
pf3
pf4
pf5

Partial preview of the text

Download Understanding Generic Programming & Classes in Java at UMD, College Park - Prof. Nelson Pa and more Study notes Computer Science in PDF only on Docsity!

Generics^ CMSC 132

Department of Computer ScienceUniversity of Maryland, College Park

Overview

Generic Programming Generic Classes

Generic Class

To use a generic class you mustprovide an actual type Valid types^ Class or interface Invalid types^ Primitive type (you must usewrappers)

Generic Class

You can define your own generic classes^ Define a class and follow the class namewith the type variable(s) in angle brackets.^ Use the type variable to define the type ofvariables, type of method arguments, returntype of a method, or in object allocation You can use any name for the type variable butusually uppercase short names (E, K) are used. Example: see Queue.java in code distribution