1 package dev.aherscu.qa.testing.utils.function; 2 3 import java.io.Serializable; 4 import java.lang.invoke.SerializedLambda; 5 import java.lang.reflect.InvocationTargetException; 6 import java.lang.reflect.Method; 7 8 interface SerializedLambdaResolvable extends Serializable { 9 10 default SerializedLambda asSerializedLambda() { 11 try { 12 Method replaceMethod = getClass().getDeclaredMethod("writeReplace"); 13 replaceMethod.setAccessible(true); 14 return (SerializedLambda) replaceMethod.invoke(this); 15 } catch (IllegalAccessException | IllegalArgumentException 16 | InvocationTargetException | NoSuchMethodException 17 | SecurityException e) { 18 throw new RuntimeException( 19 e.getClass().getSimpleName() + ": '" + e.getMessage() + "'", e); 20 } 21 } 22 23 }