Home > Programming > Java Programming
Generics in the Java Programming Language
Sort 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 ...
Source: java.sun.com
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Related Files
<>An Introduction to Java Programming
Filed under: Programming and Java ProgrammingType java Welcome to run the program. A sample run of ... You can run the Java program from the DOS prompt using. the java command. ...
Java Server Programming: Principles and Technologies
Filed under: Programming and Java Programminglargescale serverside applications using the Java programming language. ... Professional java server programming J2EE edition. Wrox Press Inc. ...
Java Programming Language SL275
Filed under: Programming and Java Programminglanguage; objectoriented programming. with the Java programming language; and ... SL275: Java Programming Language. 2 of 5. Sun Educational Services ...
Java 2 Enterprise Edition (J2EE) Certificate Program
Filed under: Programming and Java Programmingthat are available with the Java programming language. and development environment. .... database tasks and transactions from a Java program. ...
Programming mobile devices with J2ME
Filed under: Programming and Java ProgrammingJava's interfaces, with the possibility of using a layer programming structure in ... For example the access to a built-in camera in a mobile phone by means of ...
