Layers of Logic

Phase IX

Text and Types

String behaviour, text construction, generic types, and wildcards.

4 sections74 min of reading16 exercises

Explain String immutability and pooling, use the main String operations, and build changing text with StringBuilder. Then define generic classes and methods, trace type erasure, and use wildcards to express safe read and write boundaries.

When you finish this phase you can

  • State when String literals and explicitly interned values use the String pool
  • Explain why String had to be immutable before the pool could exist
  • Measure the cost of joining text with + and fix it with StringBuilder
  • Write a generic class and a generic method, and bound a type parameter
  • Explain type erasure and the run-time operations it prevents
  1. 9.1Strings: The Pool and ImmutabilityExplain String immutability, literal pooling, object identity, and why text content must be compared with equals rather than ==.The String PoolCore19 min4 exercises
  2. 9.2String Methods and StringBuilderUse the String methods needed for search, slicing, cleanup, and comparison, then build changing text efficiently with StringBuilder.StringBuilderCore17 min4 exercises
  3. 9.3GenericsDeclare generic classes and methods, apply type bounds, and explain how compile-time type checks replace unsafe Object casts.GenericsType erasureCore20 min4 exercises
  4. 9.4Wildcards: `extends` and `super`Explain generic invariance and use unbounded, extends, and super wildcards without giving up type safety.WildcardsPECSDeeper18 min4 exercises