Library containing useful tools for Java 8
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

J8+ (J8Plus) - The Missing Functional Parts of Java 8

Build Status Build Status

Coverage Status Download

views views 24h

Why J8+?

Q: Java 8 comes with newly added functional features like Lambda Expressions and Method References so why do we need this library claiming that it contains some functional features that Java 8 does not have?

A: Java 8 has nicely implemented Lambda Expressions and Method References which meke all the existing libraries really useful and reusable, yet it still lacks some useful features that can make our lives a lot easiler. J8+ provides those missing functional features to make your life easier.

Problem Examples


Java 8's JVM does still not support tail call optimization. So if you write a recursive method like the following one, you still get StackOverflowError.

public static BigInteger factorial(final BigInteger acc, final BigInteger n) {
  if (n.equals(BigInteger.ONE)) {
    return acc;
  return factorial(acc.multiply(n), n.subtract(BigInteger.ONE));

Opposite Operation

Another example is Stream in Java 8's collections. The Stream has a useful method called filter, yet, unlike Scala, it does not have a method like filterNot which does the opposite operation. Let's say you need to get all non empty String from the list. You do something like this using functional features in Java 8.

List<String> nonEmptyStrings =
                                   .filter(text -> !text.isEmpty())

It can be even more concise with Method References, but unfortunate, you can't use it as Stream does not have the opposite operation method of filter. So if it's taking all empty Strings you do like

List<String> nonEmptyStrings =
                                   .filter(String::isEmpty) // no filterNot method in Stream

But you can't use a method reference to filter out the empty String.

Solutions using J8+


StackOverflowError when using recursive method can be solved using Trampoline provided in J8+. It requires only a little changes in your code.

public static TailCallable<BigInteger> factorial(final BigInteger acc, final BigInteger n) {
  if (n.equals(BigInteger.ONE)) {
    return done(acc);
  return () -> factorial(acc.multiply(n), n.subtract(BigInteger.ONE));

Now, you don't need to worry about StackOverflowError.

Opposite Operation

Opposite operation when using method reference can easily be done using a higher-order function provided by J8+.

List<String> nonEmptyStrings =

It filters out all empty String values and takes only non-empty ones.

More About J8+

Please check out J8+ Wiki (work in progress)

Get J8+


  • Add maven repository


  • Add dependency




  • Add maven repository

    In build.gradle, add the following repository to repositories.

maven {
  url  ""


repositories {
  maven {
    url  ""
  • Add Dependency
compile group: 'cc.kevinlee', name: 'j8plus', version: '0.0.15'


compile "cc.kevinlee:testosterone:0.0.15"