Skip to content

Port Optional to java 6 as faithfully as possible while maintaining easy migration

License

Notifications You must be signed in to change notification settings

dmstocking/support-optional

Repository files navigation

Download Build Status Coverage Status

support-optional

support-optional provides a Java 9 optional that supports Java 6, Android and RetroLambda development while having an easy migration to the real optional class. This library is much in the spirit of ActionBarSherlock that it was only designed to be a removed.

It has been deprecated from inception with the intention that you could some day throw it away.
--Jake Wharton

Other backports have various problems like different class names, slightly different behavior or interface default methods. These make it harder to use and migrate to the real Java 9 optional class. So here is yet another optional backport, so you don't have to waste your time writing one.

Download

Make sure you have the jcenter repository in your root build.gradle

repositories {
      jcenter()
}

Then add the following to your modules build.gradle file

dependencies {
      compile 'com.github.dmstocking:support-optional:1.2'
}

Migration

Perform the following replacement regex

s/com\.github\.dmstocking\.optional\.//g

This could be done with find and sed in your project folder via

find . -name "*.java" -exec sed -i 's/com\.github\.dmstocking\.optional\.//g' {} \;

or with an IDE so a search and replace without regex of com.github.dmstocking.optional. with nothing over your entire src directory.

Unavailable Methods

- Optional<T>::stream()
- OptionalInt::stream()
- OptionalLong::stream()
- OptionalDouble::stream()

Because this library does not backport streams, there is no stream method on any of the Optional classes.

License

Copyright 2017 David Stocking

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Port Optional to java 6 as faithfully as possible while maintaining easy migration

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages