<commit_before># Using Java 7 & 8 Features on Android

Feeling like you're stuck in 2006 while developing apps and libraries for Android?

Don't worry, you're not alone. However, there's a solution!

To help bring Android Java development into the modern era, I've tested and compiled a list of Java 7 and 8 features that will work on Android. Some of them, I discovered through a bit of testing and modding, while others depend on libraries maintained by others. Without further BS, here's a list of everything that can be used without issues on at least Android 2.2+.


## Possible Features

* Try with resources (auto closing file handlers)
* String switches
* Multiple exception caught in one catch block
* Integer (and binary) literals for readability
* Type inference on collections (a.k.a. "diamonds")
* [Java 8 lambdas (instructions coming soon)](https://github.com/orfjackal/retrolambda)
* [Java 7 fork-join (instructions coming soon)](http://gee.cs.oswego.edu/dl/concurrency-interest/index.html)


## Things that don't Work

* Java 7 file API (java.nio.*) because some native code needs ported
* File change notifications (watch/notify file api stuff)
* Invoke Dynamic and features that rely on it (would require modifying Dalvik to support it)


## Setting up on Intellij IDEA 13 (and probably Android Studio)

The new Intellij finally has a built in option to override core libraries of Android, making much of the above far easier.


1. Clone this project or grab core.jar from the libs directory.
2. Enable overriding the Android core libraries by going to File → Settings → Compiler → Android Compilers
![alt text](imgs/core-libs.png "Enable overriding Android core libraries")<commit_msg>Modified setup instructions for Intellij IDEA 13 to make it clear it does not work for IDEA 12.<commit_after># Using Java 7 & 8 Features on Android

Feeling like you're stuck in 2006 while developing apps and libraries for Android?

Don't worry, you're not alone. However, there's a solution!

To help bring Android Java development into the modern era, I've tested and compiled a list of Java 7 and 8 features that will work on Android. Some of them, I discovered through a bit of testing and modding, while others depend on libraries maintained by others. Without further BS, here's a list of everything that can be used without issues on at least Android 2.2+.


## Possible Features

* Try with resources (auto closing file handlers)
* String switches
* Multiple exception caught in one catch block
* Integer (and binary) literals for readability
* Type inference on collections (a.k.a. "diamonds")
* [Java 8 lambdas (instructions coming soon)](https://github.com/orfjackal/retrolambda)
* [Java 7 fork-join (instructions coming soon)](http://gee.cs.oswego.edu/dl/concurrency-interest/index.html)


## Things that don't Work

* Java 7 file API (java.nio.*) because some native code needs ported
* File change notifications (watch/notify file api stuff)
* Invoke Dynamic and features that rely on it (would require modifying Dalvik to support it)


## Setting up on Intellij IDEA 13 (and probably Android Studio)

The new Intellij finally has a built in option to override core libraries of Android, making much of the above far easier. The instructions below take advantage of this and allow us to override the core libraries with a jar within Intellij IDEA normal build process. If using Intellij IDEA 12, you'll have to use the old fallback directions as this will not work


1. Clone this project or grab core.jar from the libs directory.
2. Enable overriding the Android core libraries by going to File → Settings → Compiler → Android Compilers
![alt text](imgs/core-libs.png "Enable overriding Android core libraries")
{'fraction_non_alphanumeric': 0.06219839142091153, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 4.552083333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1285445', 'n_tokens_mistral': 1027, 'n_tokens_neox': 925, 'n_words': 544}