本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}