optional: java.util.Optional module (factories, extraction, orElse vs orElseGet, anti-patterns, Stream interop, JSpecify contrast)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6gdUKYmBw6bUKcM7t
This commit is contained in:
Ankur
2026-11-25 22:58:57 +05:30
co-authored by Claude Sonnet 5.5
parent cca173d104
commit 47e4ccbefa
25 changed files with 793 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
1 isPresent+get : ANKUR | map+orElse : ANKUR
2 Optional field : java.io.NotSerializableException: java.util.Optional
2 nullable field : serialized OK, getEmail() = Optional[[email protected]]
3 greet(empty) : Hello, guest
3 greet(null) : NullPointerException, Cannot invoke "java.util.Optional.orElse(Object)" because "name" is null
4 return null : NullPointerException, Cannot invoke "java.util.Optional.map(java.util.function.Function)" because the return value of "com.ankurm.optional.AntiPatternsDemo.brokenLookup()" is null
4 return empty() : 0
5 of(map.get(..)) : NullPointerException (use ofNullable)
5 ofNullable : Optional.empty
6 Optional<List> : empty list wrapped = Optional[[]] | plain list = []
6 states : Optional<List> has 3 (empty, present-empty, present-full), List has 2