当前位置: 首页>>代码示例>>Java>>正文


Java VarHandle.AccessMode方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:VarHandleBaseTest.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:VarHandleBaseTest.java

示例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[]{});
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:VarHandleTestReflection.java

示例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[]{});
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:VarHandleTestReflection.java

示例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[]{});
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:VarHandleTestReflection.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:VarHandleTestReflection.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:VarHandleTestReflection.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:VarHandleTestAccessModeMethodNames.java

示例9: toAccessMode

import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
VarHandle.AccessMode toAccessMode() {
    return VarHandle.AccessMode.valueOf(name());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:VarHandleBaseTest.java

示例10: accessModes

import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
static List<VarHandle.AccessMode> accessModes() {
    return Stream.of(VarHandle.AccessMode.values()).collect(toList());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:VarHandleBaseTest.java

示例11: testMethodName

import java.lang.invoke.VarHandle; //导入方法依赖的package包/类
@Test(dataProvider = "accessModesProvider")
public void testMethodName(VarHandle.AccessMode am) {
    assertEquals(am.methodName(), toMethodName(am.name()));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:VarHandleTestAccessModeMethodNames.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:VarHandleTestAccessModeMethodNames.java


注:本文中的java.lang.invoke.VarHandle.AccessMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。