How can I invoke a method on an object using the Reflection API?

Here is a way: Object yourObject = ...; Class clazz = yourObject.getClass(); Method setter = clazz. GetMethod("setString", String. Class); // You need to specify the parameter types Object params = new Object{"New String"}; setter.

Invoke(this, params); // 'this' represents the class from were you calling that method. // If you have a static method you can pass 'null' instead.

You can do this, Class cls = obj.getClass(); Method m = cls. GetMethod("yourMethod", String. Class); // assuming there is a method of signature yourMethod(String x); m.

Invoke(obj, "strValue").

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions