當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodHandles.privateLookupIn方法代碼示例

本文整理匯總了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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:PrivateLookupInTests.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:Striped64.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:PrivateLookupInTests.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:PrivateLookupInTests.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:PrivateLookupInTests.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:WhiteBox.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:WhiteBox.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PrivateLookupInTests.java

示例9: testPrimitiveClassAsTargetClass

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testPrimitiveClassAsTargetClass() throws Exception {
    MethodHandles.privateLookupIn(int.class, MethodHandles.lookup());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:PrivateLookupInTests.java

示例10: testArrayClassAsTargetClass

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testArrayClassAsTargetClass() throws Exception {
    MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:PrivateLookupInTests.java

示例11: testPrimitiveArrayClassAsTargetClass

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testPrimitiveArrayClassAsTargetClass() throws Exception {
    MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:PrivateLookupInTests.java

示例12: testNullTargetClass

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {NullPointerException.class})
public void testNullTargetClass() throws Exception {
    MethodHandles.privateLookupIn(null, MethodHandles.lookup());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:PrivateLookupInTests.java

示例13: testNullCaller

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {NullPointerException.class})
public void testNullCaller() throws Exception {
    MethodHandles.privateLookupIn(getClass(), null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:PrivateLookupInTests.java

示例14: privateLookupPublicClassExportedPackage

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
static void privateLookupPublicClassExportedPackage() throws Exception {
    MethodHandles.privateLookupIn(String.class, MethodHandles.lookup());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:TryAccess.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:TryAccess.java


注:本文中的java.lang.invoke.MethodHandles.privateLookupIn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。