Posts tagged with "java"
[Advanced Java] Optional in Java: A Return Type, Not a Cure for NullPointerException
Optional in Java on OpenJDK 21: why it was designed for return types rather than as a null replacement, its two legal states and the null reference that defeats them, all twenty methods grouped by purpose, the orElse versus orElseGet evaluation trap counted in database hits, map versus flatMap with the real javac error, the five positions where Optional makes code worse, and the three places it genuinely belongs.
Functional interfaces in java.util.function on OpenJDK 21: the shape grid behind all 43 of them, what @FunctionalInterface really checks, why an abstract equals does not break single-abstract-method status, andThen versus compose, the Predicate and Consumer combinators, the primitive specialisations and the boxing they remove, and how to write your own.
[Advanced Java] Lambda Expressions in Java: Syntax, Target Typing and Method References
Lambda expressions in Java on OpenJDK 21: every syntactic form including var parameters, target typing demonstrated by assigning one text to three interfaces, effectively-final capture with the real javac errors, what this means inside a lambda body, the four kinds of method reference, and why a bound reference evaluates its receiver eagerly.
The Java Stream API on OpenJDK 21: the source-intermediate-terminal pipeline, laziness proved with an interleaved println trace, map, filter, all three reduce overloads, collect and the Collectors factory, primitive streams and the allocation cost of boxing, and the traps around peek, findAny, stateful lambdas and parallelStream.
java.util.Collections on OpenJDK 21 organised by what its methods actually are: in-place algorithms including the binarySearch insertion point trick, nCopies returning one reference n times, the unmodifiable, synchronized and checked wrappers that are views rather than copies, checkedList catching heap pollution at insertion, and the immutable factories that replace half of them.
[Advanced Java] Comparable vs Comparator in Java: Natural Ordering and Custom Sorting
Comparable and Comparator on OpenJDK 21: the full compareTo contract, the Comparator factory and combinator API, why reversed flips every key composed so far, the int subtraction overflow bug, the TimSort IllegalArgumentException that only fires on large inputs, null keys, and sorting stability measured in comparator invocations.