|
||||||||||||||||||||||||||
|
|
HOME | SEMINARS | TALKS | ARTICLES | BOOKS | LINKS | IOSTREAMS | GENERICS | ABOUT | NEWSLETTER | CONTACT | SITEMAP | |||||||||||||||||||||||||
|
Java Generics FAQs - Glossary
|
||||||||||||||||||||||||||
|
This is a collection of answers to frequently asked questions
(FAQs) about Java Generics, a new language feature added to the Java programming
language in version 5.0 of the Java Standard Edition (J2SE 5.0).
If you want to provide feedback or have any questions regarding Java
generics, to which you cannot find an answer in this document, feel free
to send me
EMAIL
or use the
GENERICS FAQ
form.
|
|||||||||||||||||||||||||
Glossary© Copyright 2004-2006 by Angelika Langer. All Rights Reserved.In this glossary links of the form XXX.FAQnnn refer to an entry in this FAQ , link of the form JLS n.n.n refer to a paragraph in JLS3 , the Java Language Specification, 3rd Edition, and links of the form J2SE API package.class.method refer to an entry in the Java platform libraries' API documentation.
A
ABbounded type parameter
A
type
parameter
with one or more bounds.
The
type parameter bounds
restrict the set of types that can be used as
type
arguments
and give access to the methods defined by the bounds.
Example:
public class
TreeMap<Key
extends
Comparable<Key>
,Data>{
private static class Entry<K,V> { ... } ... private Entry<Key,Data> getEntry(Key key) { ... key. compareTo(p.key) ... } }
A
wildcard
with either an upper or a
lower bound
.
Example: public class Collections { A synthetic method that the compiler generates in the course of type erasure . It is sometimes needed when a type extends or implements a parameterized class or interface. Example (before type erasure): interface Comparable <A> { Example (after type erasure): interface Comparable { see also: TechnicalDetails.FAQ102 C
A view to a regular
collection that performs
a runtime type check each time an element is inserted.
Example:
List<String>
stringList
= Collections.checkedList (new ArrayList<String>() ,String.class) ; see also: ProgrammingIdioms.FAQ004 , J2SE API java.util.Collection.checkedCollection A literal of type Class . A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void , followed by the suffix " .class ". Example: if (s.getClass() == String.class ) ...
see also:
JLS 15.8.2
A translation
technique for generics where the compiler generates code for only one
representation
of a generic type or method and maps all the instantiations of the
generic
type or method to the unique representation, performing type checks and
type conversions where needed.
see also: TechnicalDetails.FAQ100
A translation
technique for generics where the compiler generates code for only one
representation
of a generic type or method and maps all the instantiations of the
generic
type or method to the unique representation, performing type checks and
type conversions where needed.
An instantiation of a generic type where all type arguments are concrete types rather than wildcards .
Examples:
List<String>
but not:Map<String,Date>
List<?
extends Number>
Map<String,?> DEenum type
A reference
type that defines a finite number of enum constants, where each enum
constant defines an instance of the enum type.
Example:
enum Season { SPRING,
SUMMER, AUTUMN, WINTER }
see also: JLS 8.9 explicit type argument specification Providing a type argument list when a generic method is invoked rather than relying on type inference . Example:
public
class Utilities {
public static <T extends Comparable> T max(T arg1, T arg2) { ... } } public class Test { public static void main(String[] args) { System.out.println(Utilities. <String>max ("abc","xyz")); } } FGgeneric typeA class or interface with one or more type parameters .generic method A method with one or more type parameters .generification
...
Hheap pollution
A
situation where a variable of a
parameterized type
refers to an object
that is not of that parameterized type.
Examples:
List ln = new
ArrayList<Number>();
List<String> ls =ln; // unchecked warning + heap pollution List<? extends Number> ln = new ArrayList<Long>(); List<Short> ls = (List<Short>) ln; // unchecked warning + heap pollution Iinstantiated methodA method created from a generic method by providing an actual type argument per formal type parameter . It is the result of either type argument inference or explicit type argument specification .instantiated type A type created from a generic type by providing an actual type argument per formal type parameter .invocation A type created from a generic type by providing an actual type argument per formal type parameter . Used to denote both the process of creating a type from a generic type or method as well as the result of that process. A type created from a generic type or a generic method by providing an actual type argument per formal type parameter . Used to denote both the process of creating a type or method from a generic type or method as well as the result of that process. JKL
see:
lower wildcard
bound
A reference type that is
used to further
describe a
wildcard
; it denotes
the family of types that are supertypes of the lower bound.
Comparable<
?
super
Long
>
MNOPparameterized typeA type created from a generic type by providing an actual type argument per formal type parameter . QRraw typeA type created from a generic type by omitting the type arguments.reification
Representing type
parameters and arguments of generic types and methods at
runtime. Reification is the opposite of
type
erasure
.
reifiable type A type whose type information is fully available at runtime, that is, a type that does not lose information in the course of type erasure . SSuppressWarnings annotationA standard annotation that suppresses warnings for the annotated part of the program. Ttype argumentA reference type or a wildcard that is used for instantiation / i nvocation of a generic type or a reference type used for instantiation / i nvocation of a generic method .type argument inference The automatic deduction of the type arguments of a generic method .type erasure The process that maps generic type s and generic methods and their instantiations / invocations to their unique byte code representation by eliding type parameters and type arguments .type parameter A place holder for a type argument . Each type parameter is replaced by a type argument when a generic type or generic method is instantiated / invoked .type parameter bound A reference type that is used to further describe a type parameter . It restricts the set of types that can be used as type arguments and gives access to the non-static methods that it defines.type safety A program is considered type-safe if the entire compiles without errors and warnings and does not raise any unexpected ClassCastExceptions at runtime.type variable A place holder for a type argument . Each type parameter is replaced by a type argument when a parameterized type or an instantiated method are created. Uunbounded wildcard
A
wildcard
without a bound. Basically it is the
"?"
wildcard.
unbounded
wildcard instantiationExample:
Pair<
?
,String>
see also: TypeArguments.FAQ102 , JLS 4.5.1 unbounded wildcard parameterized type
A
parameterized type
in which all type arguments
are
unbounded wildcards
.
Examples:
Pair<?,?>
but not:Map<?,?>
Pair<?
extends Number,? extends Number>
Synonym:
unbounded
wildcard instantiation
Map<String,?> see also: GenericTypes.FAQ302
A
warning by which the compiler indicates
that it cannot ensure
type safety
.
Example: TreeSet se t = new TreeSet();see also: TechnicalDetails.FAQ001 see: upper wildcard bound
A reference type that is
used to further
describe a
wildcard
; it denotes
the family of types that are subtypes of the upper bound.
List<?
extends
String
>
List<? extends Thread.State > List<? extends int[] > List<? extends Callable<String> > List<? extends Comparable<? super Long> > VWwildcard
A syntactic construct that
denotes a
family of types.
Examples:
?
? extends Number ? super Number see also: TypeArguments.FAQ101 , JLS 4.5.1
A reference type that is
used to further
describe the family of types denoted by a
wildcard
.
Examples:
List<?
super
String
>
List<? extends int[] > List<? extends Callable<String> > List<? extends Comparable<? super Long> > see also: TypeArguments.FAQ201 , JLS 4.5.1 wildcard capture An anonymous type variable that represents the particular unknown type that the wildcard stands for. The compiler uses the capture internally for evaluation of expressions and the term "capture of ?" occasionally shows up in error message. see also: TechnicalDetails.FAQ501
A
parameterized
type
where
at least one
type argument
is a
wildcard
(as opposed to a concrete type).
Examples:
Collection<?>
List<? extends Number> Comparator<? super String> Pair<String,?> see also: GenericTypes.FAQ301 , JLS 4.5.1 XYZCONTENT
PREVIOUS
|
||||||||||||||||||||||||||
|
|
© Copyright 1995-2005
by
Angelika Langer. All Rights Reserved.
|
|||||||||||||||||||||||||