简体   繁体   English

通过反射传递基本类型和调用方法

[英]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.

相关问题 对具有原始数字返回类型的方法的反思 - Reflection on methods with a primitive numeric return type 获取方法通过反射返回类型 - Getting a methods Return type via reflection 如何处理反射中的原始类型 - how to deal with primitive type in reflection 为什么 Java 在通过反射调用不装箱的方法时不支持访问原始返回值? - Why does Java not support accessing primitive return values when invoking methods without boxing via reflection? 如果类引用原始类型,则所有访问通过ASM生成的类的构造函数的反射方法都将引发NoClassDefFoundError。 - All reflection methods accessing constructor of class generated through ASM throw NoClassDefFoundError if class references primitive type Java反射调用具有原始类型的构造函数 - Java Reflection calling constructor with primitive types 如果type是primitive或type是object,则检入反射 - Check in reflection if type is primitive or type is object 通过调用不同的方法增加原始局部变量 - Increment primitive local variable by calling different methods 通过包装原始类型的类将原始类型作为引用传递 - Passing primitive type as pass by reference by wrapping in class of primitive type 如何通过反射获取原始包装类构造函数? - How to get primitive wrapper classes constructors via reflection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM