init
This commit is contained in:
31
src/main/java/com/newyetai/common/functions/SFunction.java
Normal file
31
src/main/java/com/newyetai/common/functions/SFunction.java
Normal file
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user