Angelika Langer - Training & Consulting
HOME | COURSES | TALKS | ARTICLES | GENERICS | LAMBDAS | IOSTREAMS | ABOUT | CONTACT | Twitter | Lanyrd | Linkedin
Books  
HOME 

GENERICS
  FAQ    
    CONTENT
    FUNDAMENTALS
    FEATURES
    PRACTICAL
    TECHNICAL
    INFORMATION
    GLOSSARY
    INDEX
    PDF VERSION
 
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.
A printable version of the FAQ documents is available in PDF format (4.5MB).

Java Generics FAQs - Glossary

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

A

B

bounded 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

bounded wildcard

A wildcard with either an upper or a lower bound .
Example:
public class Collections {
  public static <T> v oid copy
  ( List<? super T> dest, List<? extends T> src) {  // bounded wildcard parameterized types
      for (int i=0; i<src.size(); i++)
        dest.set(i,src.get(i));
  }
}
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>
  public int compareTo( that); 

final class NumericValue implements Comparable <NumericValue>
  ... 
  public  int compareTo( NumericValue t hat) { return this.value - that.value; } 
}
Example (after type erasure):
interface Comparable {
  public int compareTo( Object that);
}
final class NumericValue implements Comparable {
  ...
  public  int compareTo( NumericValue t hat)   { return this.value - that.value; }
  public  int compareTo(Object that) { return this.compareTo((NumericValue)that);  } // bridge method
}
see also: TechnicalDetails.FAQ102

C

checked collection
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

class literal

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.

see also:  TechnicalDetails.FAQ100

code specialization

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 instantiation

see: concrete parameterized type
concrete parameterized type

An instantiation of a generic type where all type arguments are concrete types rather than wildcards .

Examples:
List<String>
Map<String,Date>
but not:
List<? extends Number>
Map<String,?>
Synonyms: concrete instantiation

see also: ParameterizedTypes.FAQ101
 

D

diamond operator

The empty angle brackets <> that trigger type inference in new -expressions.

Example:

List<String> list = new ArrayList <> ();
see also: TechnicalDetails.FAQ400A

E

enum 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"));
  }
}
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

F

G

generic type
A class or interface with one or more type parameters .

Examples:

class List<E> { ... }
interface Comparable<T> { ... }
interface Map<K,V> { ... }
Synonyms:  parameterized type
Most authors use the term parameterized type as a synonym for an instantiation or an invocation of a generic type.  Some (few) authors use the term parameterized type as a synonym for generic type .
see also: GenericTypes.FAQ001 , JLS 8.1.2
generic method
A method with one or more type parameters .

Examples:

<T> void set(T arg) { ... }
<T> T[] toArray(T[] array) { ... }
see also: GenericMethods.FAQ001 , JLS 8.4.4
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.
see also: generic type

H

heap 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

I

instantiated method
A 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 .

Example:

List<Number> list = new ArrayList<Number>();
Object[] numbers2 = list.toArray(new Long[0]);          // calls method <Long>toArray
Object[] numbers1 = list.<Number>toArray(new Long[0]);  // calls method <Number>toArray

In line 1 an instantiated method with the signature Long[] toArray(Long[]) is created from the generic method <T> T[] toArray(T[] a) by replacing the formal type parameter T with the inferred actual type argument Long .
In line 2 an instantiated method with the signature Number[] toArray(Number[]) is created from the generic method <T> T[] toArray(T[] a) by replacing the formal type parameter T with the explicitly-specified actual type argument Number .

see also: TechnicalDetails.FAQ401 , TechnicalDetails.FAQ402
instantiated type
A type created from a generic type by providing an actual type argument per formal type parameter .

Examples:

List<String>                                    (created from the generic type List<E> )
Map<String,Date>                            (created from the generic type Map<K,V> )
Synonyms: instantiation parameterized type , invocation
Most authors use the terms instantiation (short for: instantiated type ) or parameterized type . The JLS and  other documents by Sun Microsystems use the terms  invocation and parameterized type .
see also: GenericTypes.FAQ001 , JLS 8.1.2
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.

Examples:

List<String>            (created from the generic type List<E> )
Map<String,Date>    (created from the generic type Map<K,V> )
Synonyms: parameterized type , instantiation , instantiated type
The JLS and  other documents by Sun Microsystems use the term  invocation for the process and result of creating a type from a generic type by replacing formal type parameters by actual type arguments. The JLS uses the term parameterized type as a synonym for the resulting type.  Most authors use the term instantiation .   This FAQ prefers the terms parameterized type and instantiation over  invocation .
Other Meanings:
The term invocation is also used in conjunction with methods and means  calling a method .
see also: GenericTypes.FAQ001 , JLS 8.1.2
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.

Examples:

List<String>                                    (created from the generic type List<E> )
Map<String,Date>                            (created from the generic type Map<K,V> )
Collections.<Number>toArray      (created from the generic method <T> T[] Collections.toArray(T[]) )
Synonyms: parameterized type , invocation
Most authors use the term instantiation . The JLS and  other documents by Sun Microsystems use the term  invocation for the process and result of creating a type from a generic type by replacing formal type parameters by actual type arguments. The JLS uses the term parameterized type as a synonym for the resulting type. The JLS has no term for the result of creating a method from a generic method.
Other Meanings:
The term instantiation is also used to denote the  creation of an instance (or object) of a type.
see also: GenericTypes.FAQ001 , JLS 8.1.2

J

K

L

lower bound

see:  lower wildcard bound

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 >
see also: TypeArguments.FAQ201 , JLS 4.5.1

M

N

O

P

parameterized type
A type created from a generic type by providing an actual type argument per formal type parameter .

Examples:

List<String>            (created from the generic type List<E> )
Map<String,Date>    (created from the generic type Map<K,V> )
Synonyms: invocation , instantiation instantiated type
One of the most blurred terms in the area of generics. The JLS uses the term parameterized type for the result of replacing formal type parameters by actual type arguments; it is a synonym for an invocation of a generic type.
Other authors use the term instantiation or instantiated type instead.  Few authors equate parameterized type with generic type .
This FAQ favors the terms parameterized type and instantiation of a generic type.
see also: GenericTypes.FAQ001 , JLS 8.1.2

Q

R

raw type
A (non-generic) type created from a generic type by omitting the type parameters ("de- generification ").

Examples:

List (created from the generic type List<E> )
Map  (created from the generic type Map<K,V> )
see also: GenericTypes.FAQ201 , JLS 4.8
reification

Representing type parameters and arguments of generic types and methods at runtime. Reification is the opposite of type erasure .
see also: TechnicalDetails.FAQ101A
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 .

Examples:

int
Number
List<?>
List
Pair<?,?>[]
but not:
List<String>
List<? extends Number>


see also: TechnicalDetails.FAQ106 , JLS 4.7

S

SuppressWarnings annotation
A standard annotation that suppresses warnings for the annotated part (e.g., method, field, class, ... etc.) of the program.

Example:

@SuppressWarnings(value={"unchecked","deprecation"})
public static void someMethod() {
  ...
  TreeSet set = new TreeSet();
  set.add(new Date(104,8,11));     // unchecked and deprecation warning suppressed
  ...
}
see also: TechnicalDetails.FAQ004 , JLS 9.6.1.5

T

type argument
A 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 .

Example:

List< ? > list = new LinkedList< String >();
see also: TypeArguments.FAQ001 , JLS 4.5.1
type inference
The automatic deduction of the type arguments of a generic method or generic type .

Example:

class Collections {
  public static <A extends Comparable<? super A>> A max (Collection<A> xs) { ... }
}

LinkedList<Long> list = new LinkedList<>();  // 1
Long y = Collections.max(list);  // 2

In line 1 the compiler infers the missing type argument ( Long ) from the lefthand side of the assignment; in line 2 it infers that the method type argument must be Long from the method argument's type.

see also: TechnicalDetails.html.FAQ400 , TechnicalDetails.html.FAQ400A , TechnicalDetails.html.FAQ401 , JLS 15.12.2.7
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 .

Example:

before type erasure:  public static <A extends Comparable<? super A>> A max (Collection <A> xs) { ... }

after type erasure:     public static Comparable max (Collection xs) { ... }

see also: TechnicalDetails.FAQ101 , JLS 4.6
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 .

Example:

interface Comparable <E>   {
  int compareTo( E other);
}
Synonyms: type variable
The Language Specification uses the terms  type parameter and  type variable as synonyms. Other authors sometimes use the term  generic parameter as a synonym for  type parameter .
see also: TypeParameters.FAQ001 , JLS 4.4
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. 

Examples:

class Enum<E extends Enum<E> > { ... }
<T extends Comparable<? super T> > void sort(List<T> list) { ... }
see also: TypeParameters.FAQ101 , JLS 4.4
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.

see also: Fundamentals.FAQ004

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. 

Example:

interface Comparable <E>   {
  int compareTo( E other);
}
Synonyms:  type parameter
The Java Language Specification uses the terms  type parameter and  type variable as synonyms.
see also: TypeParameters.FAQ001 , JLS 4.4

U

unbounded wildcard
wildcard without a bound. Basically it is the  "?" wildcard.

Example:

Pair< ? ,String>
see also:  TypeArguments.FAQ102 , JLS 4.5.1
unbounded wildcard instantiation unbounded wildcard parameterized type

parameterized type in which all type arguments are  unbounded wildcards .

Examples:

Pair<?,?>
Map<?,?>
but not:
Pair<? extends Number,? extends Number>
Map<String,?>


Synonyms: unbounded wildcard instantiation

see also: GenericTypes.FAQ302


unchecked warning

A warning by which the compiler indicates that it cannot ensure type safety .

Example:

TreeSet se t = new TreeSet();
set.add("abc");        // unchecked warning

warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.TreeSet
               set.add("abc");
                      ^
see also: TechnicalDetails.FAQ001
upper bound

see: upper wildcard bound

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

V

varargs 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 warning
   for (E element : array) list.add(element);
}


warning: [varargs] Possible heap pollution from parameterized vararg type E
        public  static <E> void addAll(List<E> list, E... array) {
                                                                                                                ^
see also: Practicalities.FAQ300A

W

wildcard
A syntactic construct that denotes a family of types.

Examples:

?
? extends Number
? super Number


see also: TypeArguments.FAQ101 , JLS 4.5.1
 

wildcard bound
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 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 instantiation

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

X

Y

Z



CONTENT separator PREVIOUS
  © Copyright 1995-2022 by Angelika Langer.  All Rights Reserved.    URL: < http://www.AngelikaLanger.com/GenericsFAQ/FAQSections/Glossary.html  last update: 14 Aug 2018