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:
co-authored by
Claude Sonnet 5.5
parent
cca173d104
commit
47e4ccbefa
@@ -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
|
||||
Reference in New Issue
Block a user