站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Java Tutorial 5.0 英文版

Summary of Generics - Java Tutorial 5.0 英文版

The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Classes and Inheritance

Summary of Generics

In summary, using generic types or methods is not difficult once you've become used to the syntax. Here are a few important points to remember when using generics:
  • Generics add compile-time type checking to the Java language allowing the compiler to catch mismatched types at compile time, instead of when a ClassCastException is thrown at runtime.

  • When using a generic type, replace the single letter between the angle brackets, (for example: <E>), with an actual type (for example: <String>).

  • Use the -Xlink:unchecked to get the most information from the compiler about unchecked or type unsafe operations.

This section discusses how to use generic types and methods. For information on how to write a generic type or method, see Generics (in the Learning the Java Language trail) by Gilad Bracha.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.