Sponsored Links

 

 

 

Generics in the Java Programming Language

Source: java.sun.com
Topic: Java Programming


Short Desciption:
JDK 1.5 introduces several extensions to the Java programming language. One of these. is the introduction of generics. This tutorial is aimed at introducing ...

 

Content Inside:
Generics in the Java Programming LanguagePage 1Generics in the Java Programming LanguageGilad BrachaJuly 5 2004Contents1 Introduction22 Defining Simple Generics33 Generics and Subtyping44 Wildcards54.1 Bounded Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . .65 Generic Methods76 Interoperating with Legacy Code106.1 Using Legacy Code in Generic Code . . . . . . . . . . . . . . . . . .106.2 Erasure and Translation . . . . . . . . . . . . . . . . . . . . . . . . .126.3 Using Generic Code in Legacy Code . . . . . . . . . . . . . . . . . .137 The Fine Print147.1 A Generic Class is Shared by all its Invocations . . . . . . . . . . . .147.2 Casts and InstanceOf . . . . . . . . . . . . . . . . . . . . . . . . . .147.3 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158 Class Literals as Runtime Type Tokens169 More Fun with Wildcards189.1 Wildcard Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . .2010 Converting Legacy Code to Use Generics2011 Acknowledgements231Page 21 IntroductionJDK 1.5 introduces several extensions to the Java programming language. One of theseis the introduction of generics.This tutorial is aimed at introducing you to generics. You may be familiar withsimilar constructs from other languages most notably C++ templates. If so youll soonsee that there are both similarities and important differences. If you are not familiarwith lookaalike constructs from elsewhere all the better; you can start afresh withoutunlearning any misconceptions.Generics allow you to abstract over types. The most common examples are container types such as those in the Collection hierarchy.Here is a typical usage of that sort:List myIntList = new LinkedList(); // 1myIntList.add(new Integer(0)); // 2Integer x = (Integer) myIntList.iterator().next(); // 3The cast on line 3 is slightly annoying. Typically the programmer knows whatkind of data has been placed into a particular list. However the cast is essential. Thecompiler can only ...

 

add to Google Reader add to Google Bookmark add to bloglines add to newsgator add to FURL add to digg add to webnews add to Netscape add to Yahoo MyWeb add to spurl.net add to diigo Bookmark newsvine Bookmark del.icio.us Bookmark @ SIMPIFY Bookmark MISTER WONG Bookmark Linkarena Bookmark icio.de Bookmark oneview Bookmark folkd.com Bookmark yigg.de Bookmark reddit Bookmark StumbleUpon Bookmark Slashdot Bookmark blinklist Bookmark technorati add to blogmarks add to blinkbits add to ma.gnolia add to smarking.com add to netvouz add to co.mments add to Connotea add to de.lirio.us

 

Related PDF Files

Persistence Models and Techniques for Java Database Programming


Topic: Java Programming

This is the Title of the Book, eMatter Edition Copyright © 2003 OReilly & Associates, Inc. All rights reserved. 22 Chapter2 CHAPTER 2 Relational Data Architecture Good sense is the most evenly ...

Introduction to Graphics Programming with Java 3D


Topic: Java Programming

Introduction to Graphics Programming with Java 3D Lecturers Doug Twilleager doug.twilleager@eng.sun.com Sun Microsystems, Inc. Tutorial notes sections Abstract Preface Lecturer information Using the ...

Java Programming


Topic: Java Programming

K Computing - Delivering Computing Knowledge Worldwide www.kcomputing.com Java Programming Course Description The course teaches the fundamentals of the Java2 programming language ...

Java Programming: A Comprehensive Hands-On Introduction


Topic: Java Programming

Java Programming: A Comprehensive Hands-On Introduction - 4 Days Course 471 Overview You Will Learn How To •Write, compile and execute Java programs •Build robust applications using Javas object ...

CIW Enterprise Developer and CIW Web Developer Series: Java ...


Topic: Java Programming

The Java Programming Fundamentals course teaches you how to write Java applications and applets. ... Exception Handling Tips. Exceptions and Inheritance ...

 

Sponsored Links