If you have an anonymous class like
Predicate isEmpty = new Predicate() {
public boolean test(String t) {
return t.isEmpt
The simple answer is: You can't. There is a related answer of Brian Goetz on this matter. For implementing lambda expressions, javac creates an INVOKEDYNAMIC
instruction which delegates the invocation to the LambdaMetafactory's bootstrap method. For the OpenJDK, this bootstrap method is then creating an implementation of the required interface at runtime using ASM.
Within the test
method, the retreived instance tester
is of this ASM-generated class such that you have no class file to read for finding out which method the Predicate
represents. In the general case, the exact decision of how to map lambda expressions to interface implementations is left to the runtime environment what makes your problem even harder. The only way to find out which method a lambda expression represents is to read the byte code of its creation, i.e. interpreting the main
method, for your example.