Files
senmesh-zc/src/main/java/com/newyetai/common/functions/SFunction.java
ran.shang 7e38b8d971 init
2025-06-11 09:42:13 +08:00

32 lines
739 B
Java

package com.newyetai.common.functions;
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;
import java.util.function.Function;
/**
* @author chenyun
* @description 序列化的Function
* @date 2020/9/16 13:38
*/
@FunctionalInterface
public interface SFunction<T, R> extends Function<T, R>, Serializable {
/**
* 解析function为SerializedLambda
*
* @return
*/
default SerializedLambda serialized() {
try {
Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
replaceMethod.setAccessible(true);
return (SerializedLambda) replaceMethod.invoke(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}