Optional

Additional

Language
Java
Version
v1.0.1 (Dec 21, 2016)
Created
Dec 19, 2016
Updated
Dec 21, 2016 (Retired)
Owner
Hadi Satrio (MrHadiSatrio)
Contributor
Hadi Satrio (MrHadiSatrio)
1
Activity
Badge
Generate
Download
Source code

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 of empty(). Why?
  • or() instead of orElse().
  • orNull() instead of orElse(null).
  • ifPresentOrElse(Consumer, Function).
  • OptionalByte, OptionalShort, OptionalFloat, and OptionalChar.

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. ;)