|
||||||||||||||||||||
HOME | COURSES | TALKS | ARTICLES | GENERICS | LAMBDAS | IOSTREAMS | ABOUT | CONTACT | | | | ||||||||||||||||||||
|
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-2022 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 B C D E F G H I J K L M N O P Q R S T U V W X Y Z 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) ... } }
see also:
TypeParameters.FAQ002
,
JLS 4.4
A
wildcard
with either an upper or a lower bound
.
Example:
public class Collections {
see also:
TypeArguments.FAQ103
,
JLS 4.5.1
bridge method
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
Cchecked collection
A view to a regular collection that performs
a runtime type check each time an element is inserted.
class literal
Example:
List<String>
stringList
= Collections.checkedList (new ArrayList<String>() ,String.class) ;
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
code sharing
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.
code
specialization
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. see also: TechnicalDetails.FAQ100 concrete parameterized typeAn 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,?>
Synonyms:
concrete
instantiation
see also:
ParameterizedTypes.FAQ101
Ddiamond operatorThe empty angle brackets <> that trigger type inference in new -expressions. Example: List<String> list = new ArrayList <> ();
see also:
TechnicalDetails.FAQ400A
Eenum type
A
reference
type that defines a finite number of enum constants, where each enum constant
defines an instance of the enum type.
explicit
type argument specification
Example:
enum
Season { SPRING, SUMMER, AUTUMN, WINTER }
see also: JLS 8.9 Providing a type argument list when a generic method is invoked rather than relying on type inference . Example: public class Utilities {Similarly for the type argument of a generic type ; it can be explicitly specified, which is the norm, or deduced via type inference . List<String> list1 = new ArrayList <String> ();
see also:
TechnicalDetails.FAQ402
,
JLS15.12
FGgeneric typeA class or interface with one or more type parameters .generic method A method with one or more type parameters .generification
Converting a legacy (non-generic) class
or interface to be a generic one.
Examples: Classes (e.g., List ) of the Collections framework in Java 1.4 have been generified (e.g., List<T> ) in Java 5.0. 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
see
also:
TechnicalDetails.FAQ050
,
JLS 4.12.2.1
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.instantiation 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. JKLlower boundsee: 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.
Example:
Comparable<
? super Long
>
MNOPparameterized typeA type created from a generic type by providing an actual type argument per formal type parameter . QRraw typeA (non-generic) type created from a generic type by omitting the type parameters ("de- generification ").reification
Representing type parameters and arguments
of generic types and methods at runtime. Reification is the opposite of
type
erasure
.
see also: TechnicalDetails.FAQ101Areifiable 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 (e.g., method, field, class, ... etc.) of the program. Ttype argumentA reference type or a wildcard that is used for instantiation / invocation of a generic type or a reference type used for instantiation / i nvocation of a generic method .type inference The automatic deduction of the type arguments of a generic method or generic type .type erasure The process that maps generic types and generic methods and their instantiations / invocations to their unique bytecode 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 program compiles without errors and warnings and does not raise any unexpected ClassCastException s 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 instantiation
unbounded
wildcard parameterized type
Example:
Pair<
?
,String>
see also:
TypeArguments.FAQ102
,
JLS 4.5.1
A
parameterized
type
in which all type arguments
are
unbounded
wildcards
.
Examples:
Pair<?,?>
but not:
Map<?,?>
Pair<? extends Number,? extends
Number>
Map<String,?>
see also: GenericTypes.FAQ302
A warning by which the compiler indicates
that it cannot ensure
type
safety
.
upper bound
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. Examples:
List<? extends
String
>
List<? extends Thread.State > List<? extends int[] > List<? extends Callable<String> > List<? extends Comparable<? super Long> > see also: TypeArguments.FAQ201 , JLS 4.5.1 Vvarargs warning
A warning by which the compiler indicates
that methods with a variable argument list can lead to
heap
pollution
.
Example: public static <E> void addAll(List<E> list, E... array) { // varargs warningsee also: Practicalities.FAQ300A Wwildcard
A syntactic construct that denotes a family
of types.
wildcard bound
Examples:
?
? extends Number ? super Number
A reference type that is used to further
describe the family of types denoted by a
wildcard
.
Examples:
List<? super
String
>
see also:
TypeArguments.FAQ201
,
JLS 4.5.1
List<? extends int[] > List<? extends Callable<String> > List<? extends Comparable<? super Long> > An anonymous type parameter 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 messages. see also: TechnicalDetails.FAQ501 wildcard parameterized type
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-2022 by Angelika Langer. All Rights Reserved. URL: < http://www.AngelikaLanger.com/GenericsFAQ/FAQSections/Glossary.html> last update: 14 Aug 2018 |