Quantcast
Channel: Active questions tagged methodhandle - Stack Overflow
Browsing all 36 articles
Browse latest View live

"Cannot cast [Ljava.lang.Object;" passing Object[] to Object... varargs

I'm struggling with a simple, fundamental Java language question that isn't making sense. I'm passing an Object[] to a method which expects varargs Object..., but the method seems to be interpreting...

View Article


MethodHandle cannot be cracked when using LambdaMetafactory?

I want to convert a Record's constructor to a Function<Object[], T> using lambdametafactory (T is a generic type), here are my codes:public record R( String a, String b) {}private static void...

View Article


`MethodHandle` slower than Reflection when accessing primitive

I would like to call a method via reflection in the most performant way possible.The method returns a primitive long.I've implemented this using both reflection and MethodHandles.I was expecting...

View Article

`MethodHandle` slower than Reflection when accessing Object

I would like to call a method via reflection in the most performant way possible.The method returns an Object.I've implemented this using both reflection and MethodHandles, I was expecting MethodHandle...

View Article

Java poor performance with non-static `VarHandle`

I was investigating if replacing a java.lang.reflect.Field.get call with a VarHandle would improve performance, but instead it got slower.From benchmarking, I can see that when the VarHandle is static,...

View Article


Is there a problem with the javadoc for MethodHandles#exactInvoker?

I'm trying to understand the exactInvoker javadoc.It reads, in part:For example, to emulate an invokeExact call to a variable method handle M, extract its type T, look up the invoker method X for T,...

View Article

What does “MethodHandle::invoke” mean in Java? [duplicate]

Look the follow code:import java.lang.invoke.MethodHandle;public class Demo { interface TFunction<T, R> { R apply(T t) throws Throwable; } public class MyMethodHandle { public final native Object...

View Article

BootstrapMethodError caused by LambdaConversionException caused by using...

I was trying to check if it is possible to use MethodHandle::invoke or MethodHandle::invokeExact as method references for a functional interface that accepts a MethodHandle and returns a generified...

View Article


lambdametafactory creation is quite slow compared to just using lambda

@Benchmarkpublic void testLambdaGeneration(Blackhole bh) { Function<Object, Object> function = a -> { if(a instanceof Alpha alpha) { return alpha.primitiveInt(); }else { throw new...

View Article


Build error "com.android.tools.r8.internal.k2: MethodHandle.invoke and...

I have a module within my app that depends on org.tensorflow:tensorflow-lite:2.15.0 library. This library in turn depends on com.google.inject:guice:5.1.0 which is the source of the build error.Below...

View Article

What is the proper MethodType for invocation of a default constructor?

Suggest the code below. To me, it looks fine: I do obtain a MethodType, which takes no parameters as input, and produces an instance of A. The default constructor of a matchesthat description, in my...

View Article

Methodhandle private method called using findVirtual

Java doc of MethodHandle says that private method should invoke via findSpecial.But in the following example I am able to invoke it via findVirtual.Could somebody please explain what am I missing...

View Article

Weird behaviour of Java MethodHandle.invokeExact

Here is a minimal working example (requires Java 22 or later):(just using libc free for elaborating the behaviour)import java.lang.foreign.*;import java.lang.invoke.MethodHandle;public class Main {...

View Article


MethodHandle - What is it all about?

I am studying new features of JDK 1.7 and I just can't get it what MethodHandle is designed for? I understand (direct) invocation of the static method (and use of Core Reflection API that is...

View Article

On signature polymorphic methods in Java-7

As far as I can tell, with the introduction of MethodHandle in Java 7 came the introduction of compiler-generated method overloads.The javadoc for MethodHandle states (I've trimmed the examples):Here...

View Article


How can I improve performance of Field.set (perhap using MethodHandles)?

I'm writing some code that calls Field.set and Field.get many many thousands of times. Obviously this is very slow because of the reflection.I want to see if I can improve performance using...

View Article
Browsing all 36 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>