mardi 28 mai 2019

Identifying the class type for arguments required in gerDeclaredMethod in java

I am using Java Reflection to invoke a method xyz with these 4 parameter types:

Set<LineItems> 
Document
String
Profiler

While using getDeclaredMethod I am required to give the method argument type. If String's argument type is String.class, what should be done for Set<LineItems>?

Also the function xyz is a default function in interface abc. This interface is being implemented in multiple other classes, so method should be reflected in this only. Here is my code:

Class c = abc.getClass();

Class args[] = new Class[4];
args[0] = Set.class;
args[1] = String.class;
args[2] = Event.class;
args[3] = Profiler.class;

Method m = c.getMethod("xyz",args) ;

I know there are multiple flaws in this. Any help?





Aucun commentaire:

Enregistrer un commentaire