本文整理汇总了Java中java.lang.invoke.VarHandle.AccessMode方法的典型用法代码示例。如果您正苦于以下问题:Java VarHandle.AccessMode方法的具体用法?Java VarHandle.AccessMode怎么用?Java VarHandle.AccessMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.VarHandle
的用法示例。
在下文中一共展示了VarHandle.AccessMode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TestAccessMode
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
TestAccessMode(TestAccessType at) {
this.at = at;
try {
VarHandle.AccessMode vh_am = toAccessMode();
Method m = VarHandle.class.getMethod(vh_am.methodName(), Object[].class);
this.returnType = m.getReturnType();
isPolyMorphicInReturnType = returnType != Object.class;
}
catch (Exception e) {
throw new Error(e);
}
}
示例2: accessModesOfType
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
static List<VarHandle.AccessMode> accessModesOfType(TestAccessType... ats) {
Stream<TestAccessMode> s = Stream.of(TestAccessMode.values());
for (TestAccessType at : ats) {
s = s.filter(e -> e.isOfType(at));
}
return s.map(TestAccessMode::toAccessMode).collect(toList());
}
示例3: methodInvocation
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void methodInvocation(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
// Try a reflective invoke using a Method
Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class);
vhm.invoke(v, new Object[]{});
}
示例4: methodHandleInvoke
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class)
public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable {
VarHandle v = handle();
// Try a reflective invoke using a MethodHandle
MethodHandle mh = MethodHandles.lookup().unreflect(
VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
// Use invoke to avoid WrongMethodTypeException for
// non-signature-polymorphic return types
Object o = (Object) mh.invoke(v, new Object[]{});
}
示例5: methodInvocationFromMethodInfo
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
// Try a reflective invoke using a Method obtained from cracking
// a MethodHandle
MethodHandle mh = MethodHandles.lookup().unreflect(
VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
Method im = info.reflectAs(Method.class, MethodHandles.lookup());
im.invoke(v, new Object[]{});
}
示例6: reflectAsFromVarHandleInvoker
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
MethodHandle mh = MethodHandles.varHandleInvoker(
accessMode, v.accessModeType(accessMode));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
}
示例7: reflectAsFromFindVirtual
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
MethodHandle mh = MethodHandles.publicLookup().findVirtual(
VarHandle.class, accessMode.methodName(), v.accessModeType(accessMode));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
}
示例8: getAccessModeReturnType
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
private static Class<?> getAccessModeReturnType(VarHandle.AccessMode am) throws Exception {
Field field_am_at = VarHandle.AccessMode.class.getDeclaredField("at");
field_am_at.setAccessible(true);
Field field_at_returnType = field_am_at.getType().getDeclaredField("returnType");
field_at_returnType.setAccessible(true);
return (Class<?>) field_at_returnType.get(field_am_at.get(am));
}
示例9: toAccessMode
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
VarHandle.AccessMode toAccessMode() {
return VarHandle.AccessMode.valueOf(name());
}
示例10: accessModes
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
static List<VarHandle.AccessMode> accessModes() {
return Stream.of(VarHandle.AccessMode.values()).collect(toList());
}
示例11: testMethodName
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider")
public void testMethodName(VarHandle.AccessMode am) {
assertEquals(am.methodName(), toMethodName(am.name()));
}
示例12: testReturnType
import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider")
public void testReturnType(VarHandle.AccessMode am) throws Exception {
assertEquals(getReturnType(am.methodName()), getAccessModeReturnType(am));
}