[英]Passing the primitive type and calling methods via reflection
I am working on a kind of Framework. 我正在研究一种框架。 Here I will have to call a particular method on a particular class with particular parameters.
在这里,我将不得不在具有特定参数的特定类上调用特定方法。 I will receive parameter values in string form.
我将以字符串形式接收参数值。
like inputs will be, 就像输入一样
class name : com.classes.MyClass 类名称:com.classes.MyClass
method name : setPrimtiveType 方法名称:setPrimtiveType
Value : "true" 值:“真”
type of value : boolean 值类型:布尔值
Here the problem is that the method I am trying to call via reflection accepts primitive type. 这里的问题是我试图通过反射调用的方法接受原始类型。 this type is also an input to set the particular parameter.
此类型也是设置特定参数的输入。
I am not getting any in reflection so this can be achieved. 我没有得到任何反思,所以可以实现这一目标。
if this is your class 如果这是你的课
class MyClass {
public static void setPrimitiveType(boolean v) {
}
}
then this is how to set boolean value 那么这就是如何设置布尔值
MyClass.class.getMethod("setPrimitiveType", boolean.class).invoke(null, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.