My problem is the following: I'm trying to use invoke dynamic but I'm having problems with findVirtual and invoke.
Class<?> returnTypeClass = Class.forName("com.etc1.foo.FIXML");
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType methodType = MethodType.methodType(returnTypeClass ,returnTypeClass); //The method which will be invoked has as a param FIXML object and return a FIXML object
MethodHandle methodHandle = lookup.findVirtual(
com.etc2.foo.GMD,
"name_method",
methodType);
I have the first problem in findVirtual, I'm getting a methodHandle with the next MethodType (GMD,FIXML)FIXML --> this is not correct because my method is "public FIXML name_method(FIXML)" and findVirtual is creating a methodHandle "public FIXML name_method(GMD,FIXML)", I understand findVirtual is using "com.etc2.foo.GMD" as a param. First question from here: How can I get findVirtual to return a methodHandle FIXML name_method(FIXML)??
The second problem comes from the first one, I think... When I invoke the method by methodHandle
com.etc1.foo.FIXML fixml;
com.etc1.foo.FIXML fixml2;
fixml2 = (FIXML) methodHandle.invoke(fixml);
I get the following error "java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(GMD,FIXML)FIXML to (Object)Object"
Actually... I have been looking into other questions and I tried different solutions and nothing worked.