java - Invoking a method with generic parms using reflection -
java - Invoking a method with generic parms using reflection -
i trying pass 2 generics known types (accumulationfunction
, resultbindings
) reflective invoke routine below, i'm having trouble. can help me understand how can achieved?
package com.amir.method.compiler; //hidden imports import java.util.set; public class compiledreferencedattributemethod implements compiledmethod { final class<?> generatedclazz; //how pass arguments below invoke routine?? final knownworkdata<accumulationfunction> accumulationfunction; final knownworkdata<set<executable<instancesetvalue>>> resultbindings; public compiledreferencedattributemethod(final int hash, final knownworkdata<accumulationfunction> accumulationfunction, final knownworkdata<set<executable<instancesetvalue>>> resultbindings) { this.generatedclazz = referencedattributemethodgenerator.get().compilemethod( "com.amir.hotspot.generatedgramethod" +hash, "dynamicgra", accumulationfunction, resultbindings); this.accumulationfunction = accumulationfunction; this.resultbindings = resultbindings; } @override public workdatavalue invokecompiled(final instance oninst, final executionparms parm, final workdatadefinition returntype, final taskcontext context) { seek { homecoming (workdatavalue) this.generatedclazz .getmethod("dynamicgra", instance.class, executionparms.class, workdatadefinition.class, taskcontext.class) .invoke(null, oninst, parm, returntype, this.accumulationfunction, this.resultbindings, context); } catch(exception e) { throw new executecompiledmethodexception(this.tostring(), e); } } }
as cannot overload method generics , different parameters (see: oracle’s tutorial “restrictions on generics”) don't have bother generics reflection api.
there no ambiguity, can method that:
method m = this.generatedclazz.getmethod("dynamicgra", instance.class, executionparms.class, workdatadefinition.class, knownworkdata.class, knownworkdata.class, taskcontext.class);
then invoked null means dynamicgra must static, if it's not case must pass instance of generatedclazz on want phone call method :
object instance = this.generatedclazz.newinstance(); // new 1 or other reference of generatedclazz m.invoke(instance, oninst, parm, returntype, this.accumulationfunction, this.resultbindings, context);
java generics reflection
Comments
Post a Comment