org.owasp.shim.Java8Shim Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java8-shim Show documentation
Show all versions of java8-shim Show documentation
Backports @since Java 9 collection factories like List.of onto
Java8 in a way that uses the real ones where available, falls back
to a conforming implementation on Java8 and JIT compiles well.
The newest version!
package org.owasp.shim;
import java.util.*;
/**
* Static adapters for Java 9 APIs that we need to support on Java 8.
*/
@SuppressWarnings("JavadocReference")
public abstract class Java8Shim {
/** Statically import this and do `j8.listOf(...)`. */
public static Java8Shim j8() { return instance; }
Java8Shim() {} // Not public so there can only be one instance loaded below.
private static final Java8Shim instance;
static {
Object _instance;
try {
try {
// This is compiled with -release 1.9 in a separate project.
_instance = Class.forName("org.owasp.shim.ForJava9AndLater").newInstance();
} catch (Error e) {
// This is co-located with this project and is a fall-back.
_instance = Class.forName("org.owasp.shim.ForJava8").newInstance();
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new Error(e);
}
instance = (Java8Shim) _instance;
}
/**
* {@link java.util.List.of}
*/
public abstract List listOf();
/**
* {@link java.util.List.of}
*/
public abstract List listOf(T a);
/**
* {@link java.util.List.of}
*/
public abstract List listOf(T a, T b);
/**
* {@link java.util.List.of}
*/
public abstract List listOf(T a, T b, T c);
/**
* {@link java.util.List.of}
*/
public abstract List listOf(T... els);
/**
* {@link java.util.List.copyOf}
*/
public abstract List listCopyOf(Collection extends T> c);
/**
* {@link java.util.Map.copyOf}
*/
public abstract Map mapCopyOf(Map extends K, ? extends V> m);
/**
* {@link java.util.Map.entry}
*/
public abstract Map.Entry mapEntry(K key, V value);
/**
* {@link java.util.Map.ofEntries}
*/
public abstract Map mapOfEntries(Map.Entry... entries);
/**
* {@link java.util.Set.of}
*/
public abstract Set setOf();
/**
* {@link java.util.Set.of}
*/
public abstract Set setOf(T a);
/**
* {@link java.util.Set.of}
*/
public abstract Set setOf(T a, T b);
/**
* {@link java.util.Set.of}
*/
public abstract Set setOf(T a, T b, T c);
/**
* {@link java.util.Set.of}
*/
public abstract Set setOf(T... els);
/**
* {@link java.util.Set.copyOf}
*/
public abstract Set setCopyOf(Collection extends T> c);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy