当前位置: 首页>>代码示例>>Java>>正文


Java LambdaMetafactory.metafactory方法代码示例

本文整理汇总了Java中java.lang.invoke.LambdaMetafactory.metafactory方法的典型用法代码示例。如果您正苦于以下问题:Java LambdaMetafactory.metafactory方法的具体用法?Java LambdaMetafactory.metafactory怎么用?Java LambdaMetafactory.metafactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.invoke.LambdaMetafactory的用法示例。


在下文中一共展示了LambdaMetafactory.metafactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    l = MethodHandles.lookup();
    h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
    MethodType X = mt(int.class, LambdaReceiver.class);
    MethodType A = mt(int.class, LambdaReceiver_A.class);
    MethodType mti = mt(IA.class);
    CallSite cs = LambdaMetafactory.metafactory(l, "m", mti,A,h,X);
    IA p = (IA)cs.dynamicInvoker().invoke();
    LambdaReceiver_A lra = new LambdaReceiver_A();
    try {
        p.m(lra);
    } catch (ClassCastException cce) {
        return;
    }
    throw new AssertionError("CCE expected");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:LambdaReceiver.java

示例2: accessInstanceMethodWithFunction

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
@Test
public void accessInstanceMethodWithFunction() throws Throwable {

    SimpleBean simpleBeanInstance = new SimpleBean();

    MethodHandles.Lookup caller = MethodHandles.lookup();
    MethodType getter = MethodType.methodType(Object.class);

    MethodHandle target = caller.findVirtual(SimpleBean.class, "getObj", getter);
    MethodType func = target.type();
    System.out.println(func);
    System.out.println(func.generic());
    CallSite site = LambdaMetafactory.metafactory(caller, "apply", MethodType.methodType(Function.class), func.generic(), target, func);

    MethodHandle factory = site.getTarget();
    Function r = (Function) factory.invoke();
    assertEquals("myCustomObject", r.apply(simpleBeanInstance));

}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:20,代码来源:LambdaBeanAccessAtRuntimeTest.java

示例3: accessObjectInstanceMethod

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
@Test
public void accessObjectInstanceMethod() throws Throwable {

    SimpleBean simpleBeanInstance = new SimpleBean();

    MethodHandles.Lookup caller = MethodHandles.lookup();

    Method reflected = SimpleBean.class.getDeclaredMethod("getObj");
    MethodHandle methodHandle = caller.unreflect(reflected);

    CallSite site = LambdaMetafactory.metafactory(caller, "get", MethodType.methodType(Supplier.class, SimpleBean.class),
            MethodType.methodType(Object.class), methodHandle, MethodType.methodType(Object.class));

    MethodHandle factory = site.getTarget();
    factory = factory.bindTo(simpleBeanInstance);
    Supplier r = (Supplier) factory.invoke();
    assertEquals(simpleBeanInstance.getObj(), r.get());
}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:19,代码来源:LambdaBeanAccessAtRuntimeTest.java

示例4: mf

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private static boolean mf(MethodHandles.Lookup l) {
    try {
        LambdaMetafactory.metafactory(l, "close",
            mt(Closeable.class),mt(void.class),h,mt(void.class));
    } catch(LambdaConversionException e) {
        return true;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:T8032704.java

示例5: mf

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private static boolean mf(Class<?> k) {
    try {
        LambdaMetafactory.metafactory(l, "m",
            mt(I.class),mt(k),h,mt(void.class));
    } catch(LambdaConversionException e) {
        return true;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:T8032711.java

示例6: mf

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private static boolean mf(MethodType mti, MethodType mtf) {
    try {
        LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
    } catch(LambdaConversionException e) {
        return true;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:T8032697.java

示例7: testDirectStdNonser

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public void testDirectStdNonser() throws Throwable {
    MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);

    // Standard metafactory, non-serializable target: not serializable
    CallSite cs = LambdaMetafactory.metafactory(MethodHandles.lookup(),
                                                "test", MethodType.methodType(Predicate.class),
                                                predicateMT, fooMH, stringPredicateMT);
    Predicate<String> p = (Predicate<String>) cs.getTarget().invokeExact();
    assertNotSerial(p, fooAsserter);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:SerializedLambdaTest.java

示例8: testDirectStdSer

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public void testDirectStdSer() throws Throwable {
    MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);

    // Standard metafactory, serializable target: not serializable
    CallSite cs = LambdaMetafactory.metafactory(MethodHandles.lookup(),
                                                "test", MethodType.methodType(SerPredicate.class),
                                                predicateMT, fooMH, stringPredicateMT);
    assertNotSerial((SerPredicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:SerializedLambdaTest.java

示例9: createCallSite

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private static CallSite createCallSite(String signatureName, MethodHandles.Lookup lookup, MethodHandle methodHandle,
		MethodType instantiatedMethodType, MethodType signature, Class<?> interfaceClass) throws LambdaConversionException {
	return LambdaMetafactory.metafactory(
			lookup, 
			signatureName,
			MethodType.methodType(interfaceClass), 
			signature, 
			methodHandle, 
			instantiatedMethodType);
}
 
开发者ID:Hervian,项目名称:lambda-factory,代码行数:11,代码来源:LambdaFactory.java

示例10: makeDeserializationFunc

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private ParseFromBytes makeDeserializationFunc(Class<?> type, ParseFromBytes func) {
    try {
        MethodType originFuncArgs = MethodType.methodType(type, byte[].class);
        MethodType targetFuncArgs = MethodType.methodType(Object.class, byte[].class);
        MethodType targetClass = MethodType.methodType(ParseFromBytes.class);
        MethodHandle originFuncHandle = caller.findStatic(type, "parseFrom", originFuncArgs);
        CallSite callSite = LambdaMetafactory.metafactory(caller, "parseFormData", targetClass, targetFuncArgs,
                originFuncHandle, originFuncArgs);
        MethodHandle factory = callSite.getTarget();
        func = (ParseFromBytes) factory.invoke();
    } catch (Throwable e) {
        log.error("makeDeserializationFunc error ..", e);
    }
    return func;
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:16,代码来源:ProtobufFastSerialize.java

示例11: getConstructorAs

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
protected <T, R> T getConstructorAs(Class<T> targetClass, String methodName, Class<? extends R> clazz, Class<?>... args) {
    try {
        MethodType methodType = methodType(clazz, args);
        MethodHandles.Lookup lookup = MethodHandles.lookup();
        MethodHandle handle = lookup.findConstructor(clazz, methodType(void.class, args));
        MethodType targetType = methodType(targetClass);
        CallSite callSite = LambdaMetafactory.metafactory(lookup, methodName, targetType, methodType.generic(), handle, methodType);
        return (T) callSite.getTarget().invoke();
    } catch (Throwable t) {
        throw new RuntimeException("Unable to create function for constructor of " + clazz.getName(), t);
    }
}
 
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:13,代码来源:LambdaMetaHelper.java

示例12: buildFunction

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private void buildFunction(final MethodHandles.Lookup caller, final MethodHandle methodHandle) {
	try {
		final MethodType func = methodHandle.type();
		final CallSite site = LambdaMetafactory.metafactory(caller, "apply", MethodType.methodType(Function.class),
				MethodType.methodType(Object.class, Object.class), methodHandle, MethodType.methodType(func.returnType(), func.parameterArray()));

		final MethodHandle factory = site.getTarget();
		function = (Function<BEAN, R>) factory.invoke();

	} catch (final Throwable e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:14,代码来源:LambdaGetter.java

示例13: build

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private void build(final MethodHandles.Lookup caller, final MethodHandle methodHandle) {
	try {
		final MethodType func = methodHandle.type();
		final CallSite site = LambdaMetafactory.metafactory(caller, "apply", MethodType.methodType(BiFunction.class),
				MethodType.methodType(Object.class, Object.class, Object.class), methodHandle, MethodType.methodType(func.returnType(), func.parameterArray()));

		final MethodHandle factory = site.getTarget();
		function = (BiFunction<BEAN, R, BEAN>) factory.invoke();

	} catch (final Throwable e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:14,代码来源:LambdaWither.java

示例14: build

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
private void build(final MethodHandles.Lookup caller, final MethodHandle methodHandle) {
	try {
		final MethodType func = methodHandle.type();
		final CallSite site = LambdaMetafactory.metafactory(caller, "accept", MethodType.methodType(BiConsumer.class),
				MethodType.methodType(Void.TYPE, Object.class, Object.class), methodHandle, MethodType.methodType(Void.TYPE, func.parameterArray()));

		final MethodHandle factory = site.getTarget();
		consumer = (BiConsumer<BEAN, R>) factory.invoke();

	} catch (final Throwable e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:14,代码来源:LambdaSetter.java

示例15: accessStaticMethod

import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
@Test
public void accessStaticMethod() throws Throwable {
    MethodHandles.Lookup caller = MethodHandles.lookup();
    Method reflected = SimpleBean.class.getDeclaredMethod("getStaticObj");
    MethodHandle methodHandle = caller.unreflect(reflected);
    CallSite site = LambdaMetafactory.metafactory(caller, "get", MethodType.methodType(Supplier.class), MethodType.methodType(Object.class), methodHandle,
            MethodType.methodType(Object.class));
    MethodHandle factory = site.getTarget();
    Supplier r = (Supplier) factory.invoke();
    assertEquals(SimpleBean.getStaticObj(), r.get());
}
 
开发者ID:ufoscout,项目名称:jporm,代码行数:12,代码来源:LambdaBeanAccessAtRuntimeTest.java


注:本文中的java.lang.invoke.LambdaMetafactory.metafactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。