Questions tagged [methodhandle]

Use this tag for questions regarding MethodHandle/MethodHandles Java classes from java.lang.invoke API.

MethodHandle is a Java class which is an essential part of java.lang.invoke API. It allows to create executable references to existing methods (like it's done via ) and constructors, as well as generate new handlers on the fly (for example field getters/setters, bind arguments of existing MethodHandle and so on). Unlike reflection, MethodHandles have consistent security model which allows to control the access to non-public methods.

MethodHandle exists since .

API docs (Java-9):

99 questions
0
votes
0 answers

Intelligible toString for Lambda Method References

Is there any way to get an intelligible toString for a lambda generated with a method handle? In pre-Java 8, I have been using the Function interface from Guava, and I created a script that generated functions for many of my data classes. I also…
Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40
0
votes
1 answer

Java MethodHandle

@FXML private void handleLeftButton() throws Throwable{ MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodType methodType = MethodType.methodType(void.class, ListIterator.class, Text.class); MethodHandle leftButtonClickMethod =…
0
votes
0 answers

What's the relationship between MethodHandles.foldArguments and MethodHandle.asCollector?

The Javadoc for MethodHandles.foldArguments contains this parenthetical note: (Note that dropArguments can be used to remove any arguments that either the combiner or the target does not wish to receive. If some of the incoming arguments are…
Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
0
votes
1 answer

Java 7 - MethodHandles - invokeExact() and bindTo()

Two questions regarding the MethodHandle class: Is it true that every call to invokeExact() requires type casting of the return value (except for target methods that return void or Object) ? It seems that a MethodHandle can only be bound once to a…
jaco0646
  • 15,303
  • 7
  • 59
  • 83
0
votes
1 answer

Get method handle for overloaded method

Is it possible to look up a method handle for a overloaded method in Java 7?
Kimble
  • 7,295
  • 4
  • 54
  • 77
-1
votes
1 answer

What?! 3 vs 36 MiB for a no-op 254-ary method call via a method handle

It could be shown (see below a rewritten test case) that method handles for 254-ary methods claim less memory in Java 17 than in Java 11, when compiled and run by its tools. Since no method-handle- or reflection-related features are advertised in…
-2
votes
1 answer

get csv file from jar

I have the following line of code: InputStreamReader isr = new InputStreamReader(MethodHandles.lookup().lookupClass().getResourceAsStream(csvFile)); could someone explain to a newbe: MethodHandles.lookup() lookupClass() getResourceasStream() the…
DCR
  • 14,737
  • 12
  • 52
  • 115
-2
votes
2 answers

MethodHandle Manipulation

For my work with aspectJ and invokedynamic I need to weave in an advice into a method when a pointcut matches the called method. First I have exchanged the bootstrapmethod of the invokedynamic-instruction in the script with my own one. Now in my…
Thorben
  • 953
  • 13
  • 28
1 2 3 4 5 6
7