本文整理汇总了Java中java.lang.invoke.MethodHandles.privateLookupIn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodHandles.privateLookupIn方法的具体用法?Java MethodHandles.privateLookupIn怎么用?Java MethodHandles.privateLookupIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MethodHandles
的用法示例。
在下文中一共展示了MethodHandles.privateLookupIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTargetClassInOpenModule
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
public void testTargetClassInOpenModule() throws Throwable {
// m1/p1.Type
Class<?> clazz = Class.forName("p1.Type");
assertEquals(clazz.getModule().getName(), "m1");
// ensure that this module reads m1
Module thisModule = getClass().getModule();
Module m1 = clazz.getModule();
thisModule.addReads(clazz.getModule());
assertTrue(m1.isOpen("p1", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertTrue(lookup.lookupClass() == clazz);
assertTrue(lookup.hasPrivateAccess());
// get obj field
MethodHandle mh = lookup.findStaticGetter(clazz, "obj", Object.class);
Object obj = mh.invokeExact();
}
示例2: run
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
public MethodHandles.Lookup run() {
try {
return MethodHandles.privateLookupIn(Thread.class, MethodHandles.lookup());
} catch (ReflectiveOperationException e) {
throw new Error(e);
}
}
示例3: testAllAccessCallerSameModule
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
public void testAllAccessCallerSameModule() throws Throwable {
Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, MethodHandles.lookup());
assertTrue(lookup.lookupClass() == nonPublicType);
assertTrue(lookup.hasPrivateAccess());
// get obj field
MethodHandle mh = lookup.findStaticGetter(nonPublicType, "obj", Object.class);
Object obj = mh.invokeExact();
}
示例4: testCallerDoesNotRead
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalAccessException.class})
public void testCallerDoesNotRead() throws Throwable {
// m2/p2.Type
Class<?> clazz = Class.forName("p2.Type");
assertEquals(clazz.getModule().getName(), "m2");
Module thisModule = getClass().getModule();
Module m2 = clazz.getModule();
assertFalse(thisModule.canRead(m2));
assertTrue(m2.isOpen("p2", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
}
示例5: testNotOpenToCaller
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalAccessException.class})
public void testNotOpenToCaller() throws Throwable {
// m3/p2.Type
Class<?> clazz = Class.forName("p3.Type");
assertEquals(clazz.getModule().getName(), "m3");
Module thisModule = getClass().getModule();
Module m3 = clazz.getModule();
thisModule.addReads(clazz.getModule());
assertFalse(m3.isOpen("p3", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
}
示例6: WhiteBox
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
public WhiteBox() throws ReflectiveOperationException {
Class<?> qClass = LinkedTransferQueue.class;
Class<?> nodeClass = Class.forName(qClass.getName() + "$Node");
MethodHandles.Lookup lookup
= MethodHandles.privateLookupIn(qClass, MethodHandles.lookup());
HEAD = lookup.findVarHandle(qClass, "head", nodeClass);
TAIL = lookup.findVarHandle(qClass, "tail", nodeClass);
NEXT = lookup.findVarHandle(nodeClass, "next", nodeClass);
ITEM = lookup.findVarHandle(nodeClass, "item", Object.class);
SWEEP_THRESHOLD = (int)
lookup.findStaticVarHandle(qClass, "SWEEP_THRESHOLD", int.class)
.get();
}
示例7: WhiteBox
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
WhiteBox() throws ReflectiveOperationException {
Class<?> qClass = ConcurrentLinkedQueue.class;
Class<?> nodeClass = Class.forName(qClass.getName() + "$Node");
MethodHandles.Lookup lookup
= MethodHandles.privateLookupIn(qClass, MethodHandles.lookup());
HEAD = lookup.findVarHandle(qClass, "head", nodeClass);
TAIL = lookup.findVarHandle(qClass, "tail", nodeClass);
NEXT = lookup.findVarHandle(nodeClass, "next", nodeClass);
ITEM = lookup.findVarHandle(nodeClass, "item", Object.class);
}
示例8: testPublicLookupSameModule
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalAccessException.class})
public void testPublicLookupSameModule() throws Exception {
Lookup caller = MethodHandles.publicLookup();
Lookup lookup = MethodHandles.privateLookupIn(publicType, caller);
}
示例9: testPrimitiveClassAsTargetClass
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testPrimitiveClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(int.class, MethodHandles.lookup());
}
示例10: testArrayClassAsTargetClass
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testArrayClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup());
}
示例11: testPrimitiveArrayClassAsTargetClass
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testPrimitiveArrayClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup());
}
示例12: testNullTargetClass
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {NullPointerException.class})
public void testNullTargetClass() throws Exception {
MethodHandles.privateLookupIn(null, MethodHandles.lookup());
}
示例13: testNullCaller
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(expectedExceptions = {NullPointerException.class})
public void testNullCaller() throws Exception {
MethodHandles.privateLookupIn(getClass(), null);
}
示例14: privateLookupPublicClassExportedPackage
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
static void privateLookupPublicClassExportedPackage() throws Exception {
MethodHandles.privateLookupIn(String.class, MethodHandles.lookup());
}
示例15: privateLookupNonPublicClassExportedPackage
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
static void privateLookupNonPublicClassExportedPackage() throws Exception {
Class<?> clazz = Class.forName("java.lang.WeakPairMap");
MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
}