Awesome
Optional
– Java 8 Optional-like APIs for everyone
Differences compared to other Optional-like APIs
Optional | Java 8's Optional | Guava's Optional | Optio | |
---|---|---|---|---|
Required JDK version | 1.7 | 1.8 | 1.6 | 1.7 |
Android-compatible | Yes | Only for API 24 (Nougat) and up | Yes | Yes |
Serializable | Yes | No | Yes | No |
Support for primitive types | Yes, all of them except boolean | Only for int , double , and long | None | None |
Support for functional use-cases | Partially | Yes, including filter() , flatMap() , etc. | None | None |
Unique to Optional
absent()
instead ofempty()
. Why?or()
instead oforElse()
.orNull()
instead oforElse(null)
.ifPresentOrElse(Consumer, Function)
.OptionalByte
,OptionalShort
,OptionalFloat
, andOptionalChar
.
Including Optional
to your project
Include Optional
to your Gradle project by adding it as a dependency in your build.gradle
like so:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.hadisatrio:Optional:v1.0.1'
}
Contributions
Any kind of contributions will be appreciated. PR away!
License
Optional
is published under the MIT license.
p.s., Please let me know if you're using Optional
in your projects. Drop an email at
hi[you-know-what-to-put-here]hadisatrio.com. ;)