All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ly.mybatis.mapperservice.table.lambda.SerializedLambdaHolder Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
package com.ly.mybatis.mapperservice.table.lambda;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.ly.mybatis.mapperservice.holder.CacheHolder;

import java.lang.invoke.SerializedLambda;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

@SuppressWarnings("unused")
public class SerializedLambdaHolder extends CacheHolder, SerializedLambda> {
    @Override
    public SerializedLambda produce(SFunction key) {
        return find(key);
    }

    private SerializedLambda find(SFunction function) {
        try {
            Method method = function.getClass().getDeclaredMethod("writeReplace");
            method.setAccessible(true);
            Object writeReplace = method.invoke(function);
            if (writeReplace instanceof SerializedLambda) {
                return (SerializedLambda) writeReplace;
            }
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        throw new RuntimeException("lambda序列化失败" + Arrays.deepToString(Thread.currentThread().getStackTrace()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy