rJava icon indicating copy to clipboard operation
rJava copied to clipboard

Allow J() convenience on Java 17+

Open vpinna80 opened this issue 1 month ago • 0 comments

With current implementation, some legitimate Java calls fail because of access to private methods in Java 17+, where setAccessible doesn't work anymore.

For example, the following fails though the Map class and all the methods are public:

java_iter <- J("java.util.Map")$of("A", "B")$entrySet()$iterator()

In this case, and in similar cases, you have to resort to .jcall which is cumbersome because you have to remember the actual parameter classes, and the return type.

Expected behavior:

> str(J("java.util.Map")$of("A", "B")$entrySet()$iterator())
Formal class 'jobjRef' [package "rJava"] with 2 slots
  ..@ jobj  :<externalptr> 
  ..@ jclass: chr "java/util/ImmutableCollections$Set12$1"

vpinna80 avatar Nov 12 '25 16:11 vpinna80