Category: Calling Generic Methods

  • Creating Unmodifiable Lists – Collections, Part I: ArrayList

    Creating Unmodifiable Lists Unmodifiable collections are useful to prevent a collection from accidently being modified, as doing so might cause the program to behave incorrectly. Such collections are also stored efficiently, as no bookkeeping is required to support any further modifications and data in the collection can be packed more…

  • Implications for Arrays – Generics

    Implications for Arrays Array store checks are based on the element type being a reifiable type, in order to ensure that subtype covariance between array types is not violated at runtime. In the code below, the element type of the array is String and the array store check at (1)…

  • Limitations and Restrictions on Generic Types – Generics

    11.13 Limitations and Restrictions on Generic Types In this section we take a look at implications and restrictions on generic types for instance tests, casting, arrays, variable arity parameters, exception handling, nested classes, and enum types. Reifiable Types Concrete parameterized types are used by the compiler and then translated by…

  • Lists – Collections, Part I: ArrayList

    12.1 Lists Once an array is created, its length cannot be changed. This inflexibility can be a significant drawback when the amount of data to be stored in an array is not known a priori. In Java, the structures known as lists alleviate this shortcoming. Lists are collections that maintain…