Lookup objects and setAccessible
Mandy Chung
mandy.chung at oracle.com
Wed Jan 8 19:25:32 UTC 2020
Have you looked at Lookup::revealDirect and MethodHandleInfo::reflectAs?
Mandy
On 1/8/20 5:49 AM, Kasper Nielsen wrote:
> Sorry, I could have been a bit more specific. I meant something like
> Method.setAccessible(Lookup, true)
>
> I want to base an API on lookup objects. But I want to still support some use
> cases where people rely on java.lang.reflect.Field|Constructor|Method.
> Specifically, being able to create an Executable that can be
> instantiated/invoked. So I'm looking for a way to make members
> (Field|Constructor|Method) accessible in some way using a Lookup object.
>
> Obviously, this would not be a problem if my API relied on open
> packages/modules via module-info.java and member.setAccessible(true)
> instead of using Lookup objects.
>
> /Kasper
>
> On Wed, 8 Jan 2020 at 12:11, Remi Forax <forax at univ-mlv.fr> wrote:
>> see https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/invoke/MethodHandles.html#privateLookupIn(java.lang.Class,java.lang.invoke.MethodHandles.Lookup)
>>
>> Rémi
>>
>> ----- Mail original -----
>>> De: "Kasper Nielsen" <kasperni at gmail.com>
>>> À: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
>>> Envoyé: Mercredi 8 Janvier 2020 12:14:30
>>> Objet: Lookup objects and setAccessible
>>> Hi,
>>>
>>> I'm trying to bridge some old code using java.lang.reflect and some new code
>>> that uses Lookup objects. And I'm wondering if there is some way to make
>>> a member accessible using a Lookup object? Or if open packages/modules via
>>> module-info.java + member.setAccessible(true) is the only way?
>>>
>>> Thanks
>>> Kasper
More information about the jigsaw-dev
mailing list