Questions tagged [lambda-metafactory]
23 questions
7
votes
2 answers
LambdaMetaFactory with concrete implementation of generic type
I am trying to use Java's LambdaMetaFactory to dynamically implement a generic lambda, Handler:
public class RoutingContext {
// ...
}
@FunctionalInterface
public interface Handler {
public void handle(X arg);
}
public…

Luke Hutchison
- 8,186
- 2
- 45
- 40
6
votes
1 answer
Why does LambdaMetafactory fail when using a custom functional interface (but Function works fine)?
Given:
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.function.Function;
class Testcase
{
@FunctionalInterface
…

Gili
- 86,244
- 97
- 390
- 689
5
votes
2 answers
Is there a fast approach to reflective field access?
I need a way to access fields in a reflective nature without the performance hits from standard reflection. I have figured out how to do this with methods/constructors via LambdaMetaFactory using a privileged lookup handle, however, I can't seem to…

harrisondev
- 127
- 7
5
votes
1 answer
Use LambdaMetafactory to invoke one-arg method on class instance obtained from other classloader
Based on this stackoverflow answer, I am attempting to instantiate a class using reflection and then invoke a one-argument method on it using LambdaMetafactory::metafactory (I tried using reflection, but it was rather slow).
More concretely, I want…

Alex Kleiman
- 709
- 5
- 14
5
votes
2 answers
LambdaMetafactory to access class on a different ClassLoader
I have this code which works fine:
Method getterMethod = Person.class.getDeclaredMethod("getName");
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
Class> declaringClass = getterMethod.getDeclaringClass();
Class> returnType =…

Geoffrey De Smet
- 26,223
- 11
- 73
- 120
3
votes
1 answer
How is it possible to dynamically convert a method object into a functional interface in Java?
I have a few classes that each implement an interface. From these classes I search out a method using an annotation. This method returns a boolean and always has an object as parameter, which always inherits from another fixed object. Now I want to…

zuzuri
- 45
- 6
3
votes
1 answer
Create BiConsumer from LambdaMetafactory
I'm trying to dynamically create a method reference of type BiConsumer through LambdaMetafactory.
I was trying to apply two approaches found on https://www.cuba-platform.com/blog/think-twice-before-using-reflection/ - createVoidHandlerLambda and…

Kristoff
- 326
- 2
- 13
3
votes
1 answer
How to create proxy object at runtime using LambdaMetaFactory?
How can I create proxy objects for SAM/functional interfaces using LambdaMetaFactory
ie. equivalent of
public static Object java.lang.reflect.Proxy.newProxyInstance(ClassLoader, Class>[], InvocationHandler)
Eg. I have multiple factory…

S M
- 81
- 7
3
votes
1 answer
How to access a non-static method in dynamic class with LambdaMetafactory during the runtime
I am trying to use LambdaMetafactory to replace reflection,but I have a problem.If I use a specific class then it works well,just like this:
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType type =…

liyixin
- 33
- 3
2
votes
1 answer
LambdaMetaFactory and Private Methods
I would like to use LambdaMetaFactory to efficiently access a private method.
public class Foo {
private void bar() { // here's what I want to invoke
System.out.println("bar!");
}
}
I know it is not a security violation, because the…

Dragon
- 173
- 10
2
votes
2 answers
LambdaMetaFactory boxing / unboxing parameters and return types
I've got the following two methods:
public static IGetter createGetterViaMethodname( final Class clazz, final String methodName,
final Class fieldType )
…

Marcel
- 1,509
- 1
- 17
- 39
2
votes
2 answers
How to instantiate an object using LambdaMetaFactory?
I have an interface Action:
package action;
public interface Action {
public String act();
}
Class SimpleAction:
package action;
public class SimpleAction implements Action {
String action;
public SimpleAction() {}
public…

John Doe
- 157
- 1
- 10
1
vote
1 answer
LambdaMetaFactory with Generic Static Methods?
So I'm creating a library that allows users to pass a Class> and collect all static methods with a specific annotation (and other criteria, such as a certain parameter count and types) and convert them into lambda FunctionalInterfaces that my…

TypeMonkey
- 25
- 3
1
vote
1 answer
How should one use LambdaMetafactory to generate an invoke dynamic callsite
I am trying to work out how to use LambdaMetafactory to generate a usable callSite.
Here's my latest Groovy script attempt. I have tried multiple permutations of parameters and cannot get the second getter based example to work.
The first example I…

WILLIAM WOODMAN
- 1,185
- 5
- 19
- 36
1
vote
1 answer
Java lambda meta factory
CallSite lambdaFactory = LambdaMetafactory.metafactory(
lookup,
"call",
MethodType.methodType(BiConsumer.class),
MethodType.methodType(void.class,Long.class),
lookup.findVirtual(CallClass.class, "call",
…

Eswer KM
- 11
- 1