mybatis plus中的LambdaQueryWrapper根据Lambda表达式获取字段的原理
参照地址 https://blog.csdn.net/leisurelen/article/details/105980615
自我实现方式:也是看上述文章而来
import java.io.Serializable; import java.lang.invoke.SerializedLambda; import java.lang.reflect.Method; import java.util.function.Function; public class LambdaTest { public static void main(String[] args) throws Exception { SerializedLambda serializedLambda = doSFunction(TestDemo::getId); System.out.println("方法名:" + serializedLambda.getImplMethodName()); System.out.println("类名:" + serializedLambda.getImplClass()); } private static <T, R> java.lang.invoke.SerializedLambda doSFunction(MFunction<T, R> func) throws Exception { // 直接调用writeReplace Method writeReplace = func.getClass().getDeclaredMethod("writeReplace"); writeReplace.setAccessible(true); //反射调用 Object sl = writeReplace.invoke(func); java.lang.invoke.SerializedLambda serializedLambda = (java.lang.invoke.SerializedLambda) sl; return serializedLambda; } } @FunctionalInterface interface MFunction<T, R> extends Function<T, R>, Serializable { }