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


Java ValueConversions.identity方法代码示例

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


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

示例1: computeReturnConversion

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
/**
 * The typed target will be called according to targetType.
 * The adapter code will in fact see the raw result from internalType,
 * and must box it into an object.  Produce a converter for this.
 */
private static MethodHandle computeReturnConversion(
        MethodType targetType, MethodType internalType) {
    Class<?> tret = targetType.returnType();
    Class<?> iret = internalType.returnType();
    Wrapper wrap = Wrapper.forBasicType(tret);
    if (!iret.isPrimitive()) {
        assert(iret == Object.class);
        return ValueConversions.identity();
    } else if (wrap.primitiveType() == iret) {
        return ValueConversions.box(wrap);
    } else {
        assert(tret == double.class ? iret == long.class : iret == int.class);
        return ValueConversions.boxRaw(wrap);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:21,代码来源:FromGeneric.java

示例2: makeInstance

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
Adapter makeInstance(MethodType type, MethodHandle genericTarget) {
    genericTarget.getClass();  // check for NPE
    MethodHandle convert = returnConversion;
    if (primsAtEndOrder != null)
        // reorder arguments passed to genericTarget, if primsAtEndOrder
        throw new UnsupportedOperationException("NYI");
    if (type == entryType) {
        if (convert == null)  convert = ValueConversions.identity();
        return adapter.makeInstance(entryPoint, invoker, convert, genericTarget);
    }
    // my erased-type is not exactly the same as the desired type
    assert(type.erase() == entryType);  // else we are busted
    if (convert == null)
        convert = computeReturnConversion(type, rawEntryType, true);
    // retype erased reference arguments (the cast makes it safe to do this)
    MethodType tepType = type.insertParameterTypes(0, adapter.getClass());
    MethodHandle typedEntryPoint =
        AdapterMethodHandle.makeRetypeRaw(tepType, entryPoint);
    return adapter.makeInstance(typedEntryPoint, invoker, convert, genericTarget);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:21,代码来源:ToGeneric.java

示例3: makeReferenceIdentity

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
static MethodHandle makeReferenceIdentity(Class<?> refType) {
    MethodType lambdaType = MethodType.genericMethodType(1).invokerType();
    Name[] names = arguments(1, lambdaType);
    names[names.length - 1] = new Name(ValueConversions.identity(), names[1]);
    LambdaForm form = new LambdaForm("identity", lambdaType.parameterCount(), names);
    return SimpleMethodHandle.make(MethodType.methodType(refType, refType), form);
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:8,代码来源:MethodHandleImpl.java

示例4: identity

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
/**
 * Produces a method handle which returns its sole argument when invoked.
 * @param type the type of the sole parameter and return value of the desired method handle
 * @return a unary method handle which accepts and returns the given type
 * @throws NullPointerException if the argument is null
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle identity(Class<?> type) {
    if (type == void.class)
        throw newIllegalArgumentException("void type");
    else if (type == Object.class)
        return ValueConversions.identity();
    else if (type.isPrimitive())
        return ValueConversions.identity(Wrapper.forPrimitiveType(type));
    else
        return MethodHandleImpl.makeReferenceIdentity(type);
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:19,代码来源:MethodHandles.java

示例5: identity

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
/**
 * Produces a method handle which returns its sole argument when invoked.
 * @param type the type of the sole parameter and return value of the desired method handle
 * @return a unary method handle which accepts and returns the given type
 * @throws NullPointerException if the argument is null
 * @throws IllegalArgumentException if the given type is {@code void.class}
 */
public static
MethodHandle identity(Class<?> type) {
    if (type == void.class)
        throw newIllegalArgumentException("void type");
    else if (type == Object.class)
        return ValueConversions.identity();
    else if (type.isPrimitive())
        return ValueConversions.identity(Wrapper.forPrimitiveType(type));
    else
        return AdapterMethodHandle.makeRetypeRaw(
                MethodType.methodType(type, type), ValueConversions.identity());
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:20,代码来源:MethodHandles.java

示例6: testIdentity

import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
@Test
public void testIdentity() throws Throwable {
    //System.out.println("identity");
    MethodHandle id = ValueConversions.identity();
    Object expResult = "foo";
    Object result = id.invokeExact(expResult);
    // compiler bug:  ValueConversions.identity().invokeExact("bar");
    assertEquals(expResult, result);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:10,代码来源:ValueConversionsTest.java


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