本文整理汇总了Java中sun.invoke.util.ValueConversions.box方法的典型用法代码示例。如果您正苦于以下问题:Java ValueConversions.box方法的具体用法?Java ValueConversions.box怎么用?Java ValueConversions.box使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.invoke.util.ValueConversions
的用法示例。
在下文中一共展示了ValueConversions.box方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeBoxArgument
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
/** Factory method: Box the given argument.
* Return null if this cannot be done.
*/
static MethodHandle makeBoxArgument(MethodType newType, MethodHandle target,
int arg, Class<?> convType) {
MethodType oldType = target.type();
Class<?> src = newType.parameterType(arg);
Class<?> dst = oldType.parameterType(arg);
Class<?> boxType = Wrapper.asWrapperType(convType);
Class<?> primType = Wrapper.asPrimitiveType(convType);
if (!canBoxArgument(newType, oldType, arg, convType)) {
return null;
}
if (!VerifyType.isNullConversion(boxType, dst))
target = makeCheckCast(oldType.changeParameterType(arg, boxType), target, arg, dst);
MethodHandle boxerMethod = ValueConversions.box(Wrapper.forPrimitiveType(primType));
long conv = makeConv(OP_PRIM_TO_REF, arg, basicType(primType), T_OBJECT);
return new AdapterMethodHandle(target, newType, conv, boxerMethod);
}
示例2: 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);
}
}
示例3: testBox
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
@Test
public void testBox() throws Throwable {
//System.out.println("box");
for (Wrapper w : Wrapper.values()) {
if (w == Wrapper.VOID) continue; // skip this; no unboxed form
//System.out.println(w);
for (int n = -5; n < 10; n++) {
Object box = w.wrap(n);
MethodHandle boxer = ValueConversions.box(w.primitiveType());
Object expResult = box;
Object result = null;
switch (w) {
case INT: result = boxer.invokeExact((int)n); break;
case LONG: result = boxer.invokeExact((long)n); break;
case FLOAT: result = boxer.invokeExact((float)n); break;
case DOUBLE: result = boxer.invokeExact((double)n); break;
case CHAR: result = boxer.invokeExact((char)n); break;
case BYTE: result = boxer.invokeExact((byte)n); break;
case SHORT: result = boxer.invokeExact((short)n); break;
case OBJECT: result = boxer.invokeExact((Object)n); break;
case BOOLEAN: result = boxer.invokeExact((n & 1) != 0); break;
}
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
expResult, result);
}
}
}
示例4: testBox
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
@Test
public void testBox() throws Throwable {
//System.out.println("box");
for (Wrapper w : Wrapper.values()) {
if (w == Wrapper.VOID) continue; // skip this; no unboxed form
//System.out.println(w);
for (int n = -5; n < 10; n++) {
Object box = w.wrap(n);
MethodHandle boxer = ValueConversions.box(w.primitiveType());
Object expResult = box;
Object result = null;
switch (w) {
case INT: result = boxer.invokeExact(/*int*/n); break;
case LONG: result = boxer.invokeExact((long)n); break;
case FLOAT: result = boxer.invokeExact((float)n); break;
case DOUBLE: result = boxer.invokeExact((double)n); break;
case CHAR: result = boxer.invokeExact((char)n); break;
case BYTE: result = boxer.invokeExact((byte)n); break;
case SHORT: result = boxer.invokeExact((short)n); break;
case OBJECT: result = boxer.invokeExact((Object)n); break;
case BOOLEAN: result = boxer.invokeExact((n & 1) != 0); break;
}
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
expResult, result);
}
}
}