本文整理匯總了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());
}