Home Java 8 "Optional" bad practice?
Reply: 0

Java 8 "Optional" bad practice?

user817
1#
user817 Published in May 27, 2018, 3:37 am

I've a code:

val d = Single
            .zip<List<X>, Optional<Y>, DataContent>(
                    xSingle,
                    YSingle,
                    BiFunction { x, y ->
                        val b = if (y.isPresent()) {
                            y.get()
                        } else {
                            null
                        }
                        return@BiFunction DataContent(x, b)
                    })
            .subscribe({ data ->
                ...
            }, { t ->
                ...
            })

I've heard, that using Optional to check null value as shown in an example, is bad practice. Is that true? Why? Can someone show an alternative using RxJava2?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.354113 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO