Generics in Java parameterize classes, interfaces and methods by reference types so reusable code can retain compile-time type checks. For example,
List<String> describes a list whose elements are strings, and retrieving one has static type String. Java generic types are generally invariant: List<Integer> is not a subtype of List<Number>. Wildcards express related producer or consumer views. Type erasure means a parameterized class usually has one shared runtime class rather than a fresh class for each type argument. Primitive values use wrapper types in ordinary generic collections.[ref]https://docs.oracle.com/javase/tutorial/java/generics/. Oracle Java tutorial, Generics
// Target: computer-science.bigb
Java arrays are fixed-length objects. A two-dimensional array is an array of row-array references, so rows can have different lengths and must be allocated separately if not allocated by the initial expression.
// Target: computer-science.bigb
A
protected method is accessible to code in its package and, subject to the cross-package receiver restriction, to subclasses elsewhere. It can expose a subclass customization hook without being a public client operation. Protected access is broader than subclass-only access.// Destination: computer-science.bigb
A class declared
final cannot be subclassed. This can protect an implementation contract against overriding in an untrusted subclass. It does not by itself make the class immutable, and it rules out subclass-based customization.// Destination: computer-science.bigb
A field declared
private is hidden from ordinary external source-level access. Library methods can enforce invariants and change the representation without exposing storage to clients. Returning a mutable internal object can still undermine this encapsulation in object-oriented programming.// Destination: computer-science.bigb
There are unlisted articles, also show them or only show them.