[enhancement] 使LambdaFactory.build支持构造器

This commit is contained in:
VampireAchao
2023-03-15 10:47:52 +08:00
parent a1144f5228
commit bd83fbd973
2 changed files with 36 additions and 19 deletions

View File

@@ -12,11 +12,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.lang.invoke.LambdaConversionException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandleProxies;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
@@ -24,6 +21,7 @@ import java.util.Comparator;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* @author nasodaengineer
@@ -160,6 +158,15 @@ public class LambdaFactoryTest {
loop(count, tasks);
}
@Test
public void testConstructor() {
Constructor<Something> constructor = ((SerSupplier<Constructor<Something>>) Something.class::getConstructor).get();
Supplier<Something> constructorLambda = LambdaFactory.build(Supplier.class, constructor);
// constructorLambda can be cache or transfer
Something something = constructorLambda.get();
Assert.assertEquals(Something.class, something.getClass());
}
/**
* <p>hardCode 运行1次耗时 7600 NANOSECONDS
* <p>lambda 运行1次耗时 12400 NANOSECONDS