Proper null handling
See original GitHub issueI need to be able to observe a preference’s value (or lack of value or if it has been cleared). It’s very important to be able to keep the stream alive.
Observable<Optional<Boolean>>
//note Optional is my own custom class
Would it be possible to pass in some function to handle a custom mapping when the preference is null?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Java 8 Optional: Handling Nulls Properly - DZone
In this tutorial, learn how to handle null properties in Java 8 by using the Optional class to help reduce the number of...
Read more >Avoid Check for Null Statement in Java - Baeldung
Generally, null variables, references and collections are tricky to handle in Java code. They are not only hard to identify but also complex...
Read more >Better Null-Handling With Java Optionals - belief driven design
Until Java 8, there was no better way to handle null references than checking your variables at every turn. The new class java.util....
Read more >10. Handling nulls with Optional - Java 8 tutorial!
You can create an optional object from a nullable value using the static factoy method Optional.ofNullable . The advantage over using this method...
Read more >Best way to handle nulls in Java? [closed]
If the data comes from outside your control, systematically check for nulls and act appropriately. · If Null is within the domain of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This causes two problems
Boolean
optional. We only havetrue
andfalse
…I know RxJava2’s lack of nullability without a proper optional is rather an annoying problem to solve. Worst case scenario, an optional implementation (maybe call it
EmptyPreference<T>
) would be better than nothing.This could certainly work, but does android treat
Boolean
vsString
preferences differently? What happens if you access aBoolean
preference withsharedPrefs.getString(key)
where the key already exists in a boolean preference. Does it just returntrue
?I need to be able to completely interop with the other non-reactive ways the app (co-workers) access the preference.
Ultimately I still suggest some type of converter a la Retrofit style to enable usage of custom
Optional<T>
types.