Browse by Topic

Popular

Latest

Latest Java Posts

Diagram showing a generic array creation error and alternative approaches with List and reflection.
Java

Java Generic Array Creation: Why It Fails and How to Fix It

Explains why Java forbids generic array creation and shows practical workarounds using List, reflection, and unchecked casts.

Java genericstype erasurearray creationunchecked cast
Editorial illustration comparing a type-safe generic collection with an unchecked raw type collection in Java.
Java

Java Raw Type vs Generic: Compile-Time Safety Explained

Explains how Java raw types differ from generics, why the compiler warns, how type erasure works, and how to migrate legacy collections safely.

Java genericstype erasureraw typesunchecked warnings
Illustration of a raw type box without type parameters, causing a runtime cast error.
Java

Java Raw Type: Why It Breaks Type Safety

Learn what Java raw types are, why they remove compile-time type safety, and how to handle legacy code with parameterized types and wildcards.

genericstype safetytype erasureunchecked warnings
Diagram illustrating Java generic type erasure where type parameters are replaced with Object at compile time.
Java

Understanding Java Generic Type Erasure

Java erases generic type parameters at compile time, which affects instanceof, reflection, and arrays of parameterized types. See how bridge methods and heap pollution behave and how type tokens can preserve runtime type information.

Java genericstype erasureruntime type informationbridge methods
Illustration of Java generic invariance showing a List of Strings and a List of Objects as separate boxes with no arrow between them, emphasizing type safety.
Java

Java Generic Invariance: Type Safety in Practice

Understand why Java generics are invariant, how this differs from array covariance, and how wildcards provide flexibility without breaking type safety.

genericstype-safetywildcardstype-system
Diagram illustrating the Java PECS principle with producer extends and consumer super wildcards.
Java

Java PECS Principle: Producer Extends, Consumer Super

java pecs principle: Understand the Java PECS principle for wildcards in generics. See how producer extends and consumer super prevent type errors in collection operat...

Java GenericsWildcardsType SafetyCollections
Diagram illustrating Java generics wildcards extends and super with producer and consumer roles.
Java

Java Generics: extends vs super, When to Use Each

Learn when to use extends and super wildcards in Java generics. This guide explains the PECS rule and how to choose the right wildcard for reading versus writing collections.

Java genericswildcardsPECStype safety
Illustration of Java generic wildcard ? super showing lower bound concept
Java

Java ? super: Lower-Bounded Wildcards Explained

java ? super: Understand Java's ? super wildcard for lower-bounded generics, when to use it, and how it differs from ? extends.

Java genericswildcardslower-boundedtype safety
Java generics wildcard extends concept with a list containing subtypes of a number supertype
Java

Java ? extends: Bounded Wildcards in Generics

Understand the `? extends` wildcard in Java generics: when to use it, why it prevents adding non-null elements, and how it enables covariance.

Java GenericsWildcardsType SafetyCovariance
Diagram showing a Java list with a lower bounded wildcard accepting Integer and its supertypes Number and Object.
Java

Java Lower Bounded Wildcards: When to Use ? super T

Learn how Java lower bounded wildcards (? super T) work, when to use them, and how they differ from upper bounds in generic methods.

java genericswildcardspecstype safety