Reflect arrayElementGetter

Thiago Henrique Hupner thihup at gmail.com
Mon Dec 6 13:09:35 UTC 2021


Hi all.

I've found something weird.
If I try to "reflect" a MethodHandle.arrayElementGetter, the method
returned is not accessible, so I need to call setAccessible to be able to
use it.
The same happens to arrayElementSetter,

I'd like to know if this is the expected behavior. I was assuming that
it would return me some java.lang.reflect.Array, but it seems to be
returning
an internal implementation.

Code:
var arrayGetter = MethodHandles.arrayElementGetter(int[].class);
var method = MethodHandles.reflectAs(Method.class, arrayGetter);
method.isAccessible()
==> false
method.getName()
==> "getElementI"
method.getDeclaringClass()
==> class java.lang.invoke.MethodHandleImpl$ArrayAccessor

Thanks!


More information about the jdk-dev mailing list