
uk.co.probablyfine.matchers.function.SerializedLambdaResolvable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-8-matchers Show documentation
Show all versions of java-8-matchers Show documentation
Hamcrest matchers for JDK8's Optionals and Streams, and the java.time package
The newest version!
package uk.co.probablyfine.matchers.function;
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
interface SerializedLambdaResolvable extends Serializable {
default SerializedLambda asSerializedLambda() {
try {
Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
replaceMethod.setAccessible(true);
return (SerializedLambda) replaceMethod.invoke(this);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new RuntimeException(e.getClass().getSimpleName() + ": '" + e.getMessage() + "'", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy