本文整理汇总了Java中sun.invoke.util.ValueConversions.boxRaw方法的典型用法代码示例。如果您正苦于以下问题:Java ValueConversions.boxRaw方法的具体用法?Java ValueConversions.boxRaw怎么用?Java ValueConversions.boxRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.invoke.util.ValueConversions
的用法示例。
在下文中一共展示了ValueConversions.boxRaw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testBoxRaw
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
@Test
public void testBoxRaw() throws Throwable {
//System.out.println("boxRaw");
for (Wrapper w : Wrapper.values()) {
if (w == Wrapper.VOID) continue; // skip this; no unboxed form
if (w == Wrapper.OBJECT) continue; // skip this; no raw form
//System.out.println(w);
for (int n = -5; n < 10; n++) {
Object box = w.wrap(n);
long raw = w.unwrapRaw(box);
Object expResult = box;
MethodHandle boxer = ValueConversions.boxRaw(w.primitiveType());
Object result = null;
switch (w) {
case INT: result = boxer.invokeExact((int)raw); break;
case LONG: result = boxer.invokeExact(raw); break;
case FLOAT: result = boxer.invokeExact((int)raw); break;
case DOUBLE: result = boxer.invokeExact(raw); break;
case CHAR: result = boxer.invokeExact((int)raw); break;
case BYTE: result = boxer.invokeExact((int)raw); break;
case SHORT: result = boxer.invokeExact((int)raw); break;
case BOOLEAN: result = boxer.invokeExact((int)raw); break;
}
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
expResult, result);
}
}
}