本文整理汇总了Java中sun.invoke.util.ValueConversions.unboxRaw方法的典型用法代码示例。如果您正苦于以下问题:Java ValueConversions.unboxRaw方法的具体用法?Java ValueConversions.unboxRaw怎么用?Java ValueConversions.unboxRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.invoke.util.ValueConversions
的用法示例。
在下文中一共展示了ValueConversions.unboxRaw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeReturnConversion
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
/**
* Caller will be expecting a result from a call to {@code type},
* while the internal adapter entry point is rawEntryType.
* Also, the internal target method will be returning a boxed value,
* as an untyped object.
* <p>
* Produce a value converter which will be typed to convert from
* {@code Object} to the return value of {@code rawEntryType}, and will
* in fact ensure that the value is compatible with the return type of
* {@code type}.
*/
private static MethodHandle computeReturnConversion(
MethodType type, MethodType rawEntryType, boolean mustCast) {
Class<?> tret = type.returnType();
Class<?> rret = rawEntryType.returnType();
if (mustCast || !tret.isPrimitive()) {
assert(!tret.isPrimitive());
assert(!rret.isPrimitive());
if (rret == Object.class && !mustCast)
return null;
return ValueConversions.cast(tret);
} else if (tret == rret) {
return ValueConversions.unbox(tret);
} else {
assert(rret.isPrimitive());
assert(tret == double.class ? rret == long.class : rret == int.class);
return ValueConversions.unboxRaw(tret);
}
}
示例2: testUnboxRaw
import sun.invoke.util.ValueConversions; //导入方法依赖的package包/类
@Test
public void testUnboxRaw() throws Throwable {
//System.out.println("unboxRaw");
for (Wrapper w : Wrapper.values()) {
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 expResult = w.unwrapRaw(box);
Object box2 = w.wrapRaw(expResult);
assertEquals(box, box2);
MethodHandle unboxer = ValueConversions.unboxRaw(w.primitiveType());
long result = -1;
switch (w) {
case INT: result = (int) unboxer.invokeExact(box); break;
case LONG: result = (long) unboxer.invokeExact(box); break;
case FLOAT: result = (int) unboxer.invokeExact(box); break;
case DOUBLE: result = (long) unboxer.invokeExact(box); break;
case CHAR: result = (int) unboxer.invokeExact(box); break;
case BYTE: result = (int) unboxer.invokeExact(box); break;
case SHORT: result = (int) unboxer.invokeExact(box); break;
case BOOLEAN: result = (int) unboxer.invokeExact(box); break;
case VOID: result = (int) unboxer.invokeExact(box); break;
}
assertEquals("(w,n,box)="+Arrays.asList(w,n,box),
expResult, result);
}
}
}