Java: Cast String to primitive type dynamically
问题 I want to invoke a method by reflection in java. I have on my hand the Method instance of the method I want to invoke (so I can get the types of its parameters), in addition, I have the values of these parameters as Strings. I have an assumption that all the parameters MUST be primitives. for example, if I want to invoke the following method: public static double calc(int a, double b, String op){...} I have the parameter as a String Array: String[]: {"25", "34.45", "add"} So, how can I